我对发布的AddIn有疑问。
为了确保我可以轻松地将AddIn升级到所有用户,我实现了一个自动更新代码,该代码在两个单独的AddIn上启动时运行。
Loader AddIn 在 Workbook_open
上运行此子目录Private Sub Workbook_Open()
'''''''''''''''''''''''''''''''''''''''''''''''
' Workbook_Open
' Open the add-in and close this workbook
'''''''''''''''''''''''''''''''''''''''''''''''
Dim DateNetwork As Date
Dim DateLocal As Date
Const FilePath As String = "C:\Filepath\Add In"
On Error Resume Next
DateNetwork = FileDateTime(FilePath & "\PT Core.xlam")
DateLocal = FileDateTime(ThisWorkbook.Path & "\PT Core.xlam") 'Note: using on error resume next above means DateLocal will be 0 if there is no file, so it will always download the latest.
If DateNetwork > DateLocal Then
Workbooks("PT Core.xlam").Close savechanges:=False 'Ensure the addin has not loaded already
FileCopy FilePath & "\PT Core.xlam", ThisWorkbook.Path & "\PT Core.xlam"
End If
Workbooks.Open ThisWorkbook.Path & "\PT Core.xlam"
ThisWorkbook.Close savechanges:=False
End Sub
Main AddIn 在 Workbook_open
运行此代码时Private XLApp As CExcelEvents
Private Sub Workbook_Open()
Set XLApp = New CExcelEvents
End Sub
CExcelEvents 类
Private WithEvents App As Application
Private Sub Class_Initialize()
Set App = Excel.Application
End Sub
Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Application.Run "ContextMenu.AddToCellMenu", Target
End Sub
所有这些都允许我在应用程序级别捕获right_click事件。
打开文件时,加载程序将作为AddIn启动激活,然后启动Main AddIn。加载程序关闭,然后文件打开。 但是,AddIn会在启动时创建一个灰色的Excel实例窗口,从而给人以两个文件打开的印象。当我关闭文件时,AddIn保持加载状态,我必须手动关闭App。
我做错了吗?我似乎无法弄清楚为什么会发生这种情况。
我已经删除了我不使用的PERSONAL.XLSB。
感谢您的帮助。
答案 0 :(得分:0)
我已经找到了一些关于我的问题的解释。
我只安装了正在加载主加载项的加载程序加载项。它具有相同的行为,就像我试图从文件资源管理器中打开我的xlam文件。
我已经安装了主加载项和加载器加载项,我更改了代码如下。
Private Sub Workbook_Open()
'''''''''''''''''''''''''''''''''''''''''''''''
' Workbook_Open
' Open the add-in and close this workbook
'''''''''''''''''''''''''''''''''''''''''''''''
Dim DateNetwork As Date
Dim DateLocal As Date
Const FilePath As String = "C:\Filepath\Add In"
On Error Resume Next
DateNetwork = FileDateTime(FilePath & "\PT Core.xlam")
DateLocal = FileDateTime(ThisWorkbook.Path & "\PT Core.xlam") 'Note: using on error resume next above means DateLocal will be 0 if there is no file, so it will always download the latest.
If DateNetwork > DateLocal Then
Workbooks("PT Core.xlam").Close savechanges:=False 'Ensure the addin has not loaded already
FileCopy FilePath & "\PT Core.xlam", ThisWorkbook.Path & "\PT Core.xlam"
Workbooks.Open ThisWorkbook.Path & "\PT Core.xlam"
End If
ThisWorkbook.Close savechanges:=False
End Sub
当更新用户版本并且主加载项从加载程序启动时仍然会出现问题但是一旦用户关闭并再次打开Excel,它就会被跳过并正常工作。