什么是.xlam excel插件的入口点

我正在做一些excel addIn abc.xlam的工作。 这个addIn在excel addIns中被启用。 我想在Excel中打开一个工作表(新的或现有的)时启动一个.exe文件。 我想在打开工作簿的事件中在.xlam addIn中编写此.exe启动部分。 请告诉我,我该怎么做?

您需要访问Excel应用程序的NewWorkbook事件,因此您需要在加载插件时设置对Application对象的引用。

将下面的示例代码放在ThisWorkbook模块中:

 Option Explicit '***** Always use Option Explicit! Private WithEvents oXl As Application Private Sub oXl_NewWorkbook(ByVal Wb As Workbook) '***** Trapping the NewWorkbook event Call MsgBox("It's me again. (" & oXl.Workbooks.Count & ")", vbInformation, "Hi. Again.") '***** Your code here! End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) '***** Remove reference to oXL object Set oXl = Nothing End Sub Private Sub Workbook_Open() '***** Set reference to the current Excel application Set oXl = ThisWorkbook.Application '***** Testing the oXL object Call MsgBox("Hello, there! (" & oXl.Workbooks.Count & ")", vbInformation, "Hi") End Sub 

好的,我做到了! 我只是在现有的macros中创build一个新的function

 Private Sub MyMacro MsgBox "HI" End Sub 

然后,我从ThisWorkbook中调用这个函数

  Private Sub Workbook_Open() Run "MyMacro" Exit Sub