下面是创建 Module1.bas 并在其上存储代码。我想添加以下代码以从“Thisworkbook”触发宏。
如何在 Thisworkbook 中添加 Workbook_Open() ?
sCode ="Private Sub Workbook_Open()\r\n" + "UserForm1.Show\r\n" + "end sub"
using Excel = Microsoft.Office.Interop.Excel;
using VBIDE = Microsoft.Vbe.Interop;
VBIDE.VBComponent oModule;
String sCode;
oModule = wb.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule);
sCode ="Private Sub Workbook_Open()\r\n" +
"UserForm1.Show\r\n" +
"end sub"
oModule.CodeModule.AddFromString(sCode);