【问题标题】:Trouble running Excel Add In macro from MS Access 2010 procedure从 MS Access 2010 过程中运行 Excel Add In 宏时遇到问题
【发布时间】:2014-03-14 03:27:02
【问题描述】:

我在 MS Access 中使用 VBA 代码将查询导出为 Excel 工作簿。我有一个单独的程序应该从 MS Access 打开工作簿并运行宏来格式化工作簿。宏存储在单独的 Excel 加载项 (.xlam) 工作簿中。

我的问题:我收到 1004 无法运行宏错误,因为“找不到宏或宏已被禁用”。我尝试在 Excel 信任中心选项中启用所有宏,然后单独打开加载项工作簿并重新运行该过程。我遇到了同样的错误。

我已经在网上搜索了答案,但我没有找到任何人成功运行了存储在 MS Access 过程中的单独加载项工作簿中的宏。有人愿意尝试和帮助吗?

这是给我带来问题的 MS Access 程序:

 Private Sub RunExcelTrackerMacro(strFileName As String)
    Dim xl As Object
    ' Create excel app.
    Set xl = CreateObject("Excel.Application")

    ' Open workbook to be formatted via a macro.
    xl.Workbooks.Open (strFileName)
    xl.Visible = False

    ' Run the macro, stored in a separate add-in (.xlam) workbook.
    ' This procedure fails to run the public Call_FormatTracker macro, which
    ' is stored in an Add-In in a module called "MacroCalls." 
    xl.Run "MacroCalls.Call_FormatTracker"

    ' Save and close the workbook.
    xl.ActiveWorkbook.Close (True)
    ' Close excel app.
    xl.Quit
    Set xl = Nothing
End Sub

【问题讨论】:

    标签: vba excel ms-access-2010


    【解决方案1】:

    如何将 xl.Run 行更改为 xl.Run "Sales.xlam!Orders" 之类的内容

    不知道你的 xlam 叫什么,但只是改变以适应。

    【讨论】:

      【解决方案2】:

      我在插件中运行宏时遇到了类似的问题。虽然当我直接打开 Excel 时插件可用,但从 Access 调用 Excel 时却不可用。

      创建 Excel 对象后,添加下面的行。

      Call ReloadXLAddins(xl)
      
      
      Function ReloadXLAddins(oExcel) ' As Boolean
      
        '  Dim CurrAddin As Excel.AddIn
      
      For Each CurrAddin In oExcel.AddIns
          If CurrAddin.Installed Then
              CurrAddin.Installed = False
              CurrAddin.Installed = True
          End If
      Next CurrAddin
      

      结束函数

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-09
        • 2017-08-31
        • 1970-01-01
        相关资源
        最近更新 更多