我寫了excel VBA加載項文件(.xlam)。我也有一個導出的功能區定製(.exportedUI)。我如何創建安裝程序,以便我的用戶可以運行安裝程序來安裝Excel VBA加載項和功能區定製?自動安裝excel VBA加載項
3
A
回答
4
如果你想有一個商業工具,高級安裝有一些內置的Office加載安裝程序支持:http://www.advancedinstaller.com/user-guide/addins-tab.html
另一種方法是使用自定義代碼來配置加載項。也許這將有助於: http://www.cpearson.com/excel/installinganxla.aspx
2
我創建了一個自動安裝過程,將其添加到XLAM文件的「This Workbook」部分,以便它在文件打開時自動運行。 爲了區分安裝文件和安裝的文件,安裝版本命名爲「.install.xlam」,安裝的版本命名爲「.xlam」。 (否則,Excel有一個「對不起,Excel不能同時打開兩個工作簿具有相同的名稱。」
步驟: - 與.install.xlam 重命名XLAM文件 - 在Visual打開並編輯Basic編輯器(VBE) - 添加下列步驟爲「此工作簿」一節中VBE - 保存文件
爲了分享/安裝您的XLAM,你現在只需要要求用戶雙擊XLAM文件,根據需要啓用宏並接受以安裝插件。
如果您想稍後更新您的XLAM o n,只需雙擊它,根據需要啓用宏並拒絕安裝它。然後編輯它並保存更改。
這裏是增加「的ThisWorkbook」的代碼:
‘ (c) Willy Roche (willy.roche(at)centraliens.net)
‘ Install procedure of XLAM (library of functions)
‘ This procedure will install a file name .install.xlam in the proper excel directory
‘ The install package will be name
‘ During install you may be prompt to enable macros (accept it)
‘ You can accept to install or refuse (which let you modify the XLAM file macros or install procedure
Option Explicit
Const bVerboseMessages = False ‘ Set it to True to be able to Debug install mechanism
Dim bAlreadyRun As Boolean ‘ Will be use to verify if the procedure has already been run
Private Sub Workbook_Open()
‘ This sub will automatically start when xlam file is opened (both install version and installed version)
Dim oAddIn As Object, oXLApp As Object, oWorkbook As Workbook
Dim i As Integer
Dim iAddIn As Integer
Dim bAlreadyInstalled As Boolean
Dim sAddInName As String, sAddInFileName As String, sCurrentPath As String, sStandardPath As String
sCurrentPath = Me.Path & 「\」
sStandardPath = Application.UserLibraryPath ‘ Should be Environ(「AppData」) & 「\Microsoft\AddIns」
DebugBox (「Called from:'」 & sCurrentPath & 「‘」)
If InStr(1, Me.Name, 「.install.xlam」, vbTextCompare) Then
‘ This is an install version, so let’s pick the proper AddIn name
sAddInName = Left(Me.Name, InStr(1, Me.Name, 「.install.xlam」, vbTextCompare) – 1)
sAddInFileName = sAddInName & 「.xlam」
‘ Avoid the re-entry of script after activating the addin
If Not (bAlreadyRun) Then
DebugBox (「Called from:'」 & sCurrentPath & 「‘ bAlreadyRun = false」)
bAlreadyRun = True ‘ Ensure we won’t install it multiple times (because Excel reopen files after an XLAM installation)
If MsgBox(「Do you want to install/overwrite ‘」 & sAddInName & 「‘ AddIn ?」, vbYesNo) = vbYes Then
‘ Create a workbook otherwise, we get into troubles as Application.AddIns may not exist
Set oXLApp = Application
Set oWorkbook = oXLApp.Workbooks.Add
‘ Test if AddIn already installed
For i = 1 To Me.Application.AddIns.Count
If Me.Application.AddIns.Item(i).FullName = sStandardPath & sAddInFileName Then
bAlreadyInstalled = True
iAddIn = i
End If
Next i
If bAlreadyInstalled Then
‘ Already installed
DebugBox (「Called from:'」 & sCurrentPath & 「‘ Already installed」)
If Me.Application.AddIns.Item(iAddIn).Installed Then
‘ Deactivate the add-in to be able to overwrite the file
Me.Application.AddIns.Item(iAddIn).Installed = False
Me.SaveCopyAs sStandardPath & sAddInFileName
Me.Application.AddIns.Item(iAddIn).Installed = True
MsgBox (「‘」 & sAddInName & 「‘ AddIn Overwritten」)
Else
Me.SaveCopyAs sStandardPath & sAddInFileName
Me.Application.AddIns.Item(iAddIn).Installed = True
MsgBox (「‘」 & sAddInName & 「‘ AddIn Overwritten & Reactivated」)
End If
Else
‘ Not yet installed
DebugBox (「Called from:'」 & sCurrentPath & 「‘ Not installed」)
Me.SaveCopyAs sStandardPath & sAddInFileName
Set oAddIn = oXLApp.AddIns.Add(sStandardPath & sAddInFileName, True)
oAddIn.Installed = True
MsgBox (「‘」 & sAddInName & 「‘ AddIn Installed and Activated」)
End If
oWorkbook.Close (False) ‘ Close the workbook opened by the install script
oXLApp.Quit ‘ Close the app opened by the install script
Set oWorkbook = Nothing ‘ Free memory
Set oXLApp = Nothing ‘ Free memory
Me.Close (False)
End If
Else
DebugBox (「Called from:'」 & sCurrentPath & 「‘ Already Run」)
‘ Already run, so nothing to do
End If
Else
DebugBox (「Called from:'」 & sCurrentPath & 「‘ in place」)
‘ Already in right place, so nothing to do
End If
End Sub
Sub DebugBox(sText As String)
If bVerboseMessages Then MsgBox (sText)
End Sub
相關問題
- 1. 如何將加載項安裝到Excel的自動化加載項列表中?
- 2. 使用加載項命令自動加載Excel加載項
- 3. Powershell Excel自動彭博加載項
- 4. MS Excel 2013的自動化加載項
- 5. Excel 2013自動更新加載項?
- 6. 如何使用msi安裝程序部署VBA Excel加載項(foo.xlam)?
- 7. IE加載項安裝程序和自動安裝前提條件?
- 8. 安裝Outlook加載項
- 9. 通過Access VBA查看Excel加載項?
- 10. VBA就像部署Excel JavaScript加載項
- 11. VBA加載項問題
- 12. 自動分組Excel Excel VBA
- 13. 在Excel中自動添加加載項的單個菜單項
- 14. Excel VBA無法識別手動打開的.xlam加載項
- 15. 安裝時自動重裝
- 16. VBA加載項問題
- 17. 是否可以使用excel vba爲excel創建COM加載項?
- 18. 在VS2008安裝項目中自動安裝驅動程序
- 19. Excel VBA幫助文檔安裝
- 20. 在Excel 2007中安裝VBA宏
- 21. 從VBA調用COM加載項選項
- 22. Excel的VBA自動填充
- 23. Excel VBA自動舍入
- 24. Excel VBA自動過濾
- 25. 自動化錯誤 - VBA(EXCEL)
- 26. Excel VBA中自動篩選
- 27. sharepoint加載項多站點安裝
- 28. 無法安裝Outlook 2007的加載項?
- 29. 安裝Outlook加載項在哪裏?
- 30. VSTO(Outlook加載項)安裝部署(C#)