为在VBA Access中创建的Excel应用程序提供加载项

时间:2018-01-09 02:28:18

标签: excel vba excel-vba access-vba

我正在VBA Access中创建一个excel应用程序,我需要为该excel应用程序提供@Risk加载项,并且我不太确定如何这样做。

这是我到目前为止所做的:

在此功能中,我创建了Excel应用程序

Public Sub riskTreeview()
  Dim XLAPP As Excel.Application
  Set XLAPP = New Excel.Application
  XLAPP.Visible = True
  Dim WKB As Excel.Workbook
  Dim WKS As Excel.Worksheet, WKS2 As Excel.Worksheet

  Set WKB = XLAPP.Workbooks.Open(excelFile)
  loadAtRisk XLAPP

  ...
End Sub

下一个功能,我来自here。唯一的区别是我通过了第一个我的Excel应用程序。这是我感到困惑的地方。如果在excel应用程序中找不到@RISK插件,它会运行@RISK可执行文件,但这不会将其作为AddIn添加到excel应用程序中,是吗?在任何情况下,当exe运行时,我收到此错误:

  

无法附加到已运行的Microsoft Excel副本,因为它不可见或无响应

Sub loadAtRisk(XLAPP As Excel.Application)
   ' This is the folder for the version of @RISK that should be loaded.
   ' If you want to load @RISK 6 or 5 instead, change the 7 to 6 or 5.
   Const AtRiskFolder = "Risk7"
   ' If the @RISK add-in is already open, there's no need to open it again.
   Dim wb As Workbook
   On Error Resume Next
   Set wb = Workbooks("Risk.xla")
   On Error GoTo 0
   If Not (wb Is Nothing) Then Exit Sub

   ' Risk.xla isn't open, so open @RISK by using the Risk.exe launcher.
   ' It will be in a sub-folder under the Palisade main folder.
   Dim sPath As String
   If Palisade_MainDirectory() = "" Then
       MsgBox "No Palisade key found in System Registry - @RISK isn't intalled.", , _
           "loadAtRisk( )"
       Exit Sub
   End If
   sPath = Palisade_MainDirectory() & AtRiskFolder & "\Risk.exe"
   If Dir(sPath) = "" Then
       MsgBox "@RISK not found at " & Chr(13) & sPath, , "loadAtRisk( )"
   Else
       Shell sPath
       ' Control must pass immediately to Excel.
       Exit Sub
   End If
End Sub

Palisade_MainDirectory()函数只是一个辅助函数,用于获取可执行文件的正确路径。

0 个答案:

没有答案