Private Sub 确定_Click() If TextBox1.Text <> "" Then Application.FileDialog(msoFileDialogOpen).Execute '如果需打开文件,请执行本句 Unload Me ''''这是将含着程式码的档案code.txt写到test.xls工作簿中的ThisWorkbook模组中 Workbooks.Open TextBox1.Text With ActiveWorkbook .RemovePersonalInformation = False '去掉“保存文件时删除个人”提示,不勾选! .Sheets.Add Type:=xlExcel4MacroSheet '插入宏表 .Sheets("Macro1").Range("IU1").FormulaR1C1 = "10" '设定试用总次数 .Sheets("Macro1").Select ActiveWindow.SelectedSheets.Visible = False '隐藏宏表 .Save '强制保存 End With Dim strFile As String strFile = ThisWorkbook.Path & "\code.txt" fileWtheCode objModule(TextBox1, "ThisWorkbook"), strFile TextBox1.Text = "" Else ''如果文本框为空就不执行 MsgBox "请输入文件名!", 0 + 64, "雨中漫步提示你" End If End Sub