Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
标题很简单。如何使用 Excel 互操作将 VBA 代码添加到 Excel 文件?
您是否尝试将 VBA 代码保存在“.bas”文件中?然后,您可以尝试通过 Excel 互操作以编程方式添加代码。
如果这不起作用,为什么不在Workbook_Open事件触发时简单地添加以下代码:
Workbook_Open
Private Sub Workbook_Open() Dim sModulePath As String sModulePath = "path" ThisWorkbook.VBProject.VBComponents.Import Filename:=sModulePath End Sub