我怎样才能访问“ThisWorkbook”的Excel中的C#
下面是创buildModule1.bas和存储在其上的代码。 我想添加下面的代码来触发macros从“Thisworkbook”。
我该如何在Workbook中添加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);
var workbookMainModule = wkBk.VBProject.VBComponents.Item("ThisWorkbook"); workbookMainModule.CodeModule.AddFromString(sCode);