有没有办法在打开时将整个模块的子/函数导入到excel工作簿中?我们的想法是让旧工作簿在打开时导入更新的代码,而无需始终进入“开发”选项卡并粘贴新代码。
代码目前位于* .txt文件中。
感谢Mathieu Guindon:
Private Sub Auto_Open()
CreateModule "Module2", "your\file\path.txt"
End Sub
Public Sub CreateModule(ByRef ModuleName As String, ByRef CodeFileName As String)
Const vbext_ct_StdModule = 1
Dim vbComp As Object
Set vbComp = ModuleName
Application.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_StdModule)
vbComp.Name = ModuleName
vbComp.CodeModule.AddFromFile (CodeFileName)
End Sub