简体   繁体   中英

Excel vba | running a access macro from excel

I get the following message whenever I try to execute the following code.

Sub Refresh_Pivot()
Dim AWB As Workbook
Dim pvtTable As Object
Dim appAccess As Object

'Save workbook
Set AWB = ActiveWorkbook
AWB.Save

   'Open Access Application
   Set appAccess = CreateObject("Access.Application")
   appAccess.OpenCurrentDatabase "S:\AMA\MPF\MPF Projects\MPF Loss Emergence\MPFV4.accdb"
   appAccess.Visible = True

'Set Message bar in excel t o notify user of update process
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Retrieving information, please be patient...."



  'Execute Access Macro containing lineup of queries and scrubs
  appAccess.DoCmd.RunMacro "0_Retrieve_Scrub"  '<-- As it appears in the Macro Group in the Access Interface.


       'Close Access

       appAccess.DoCmd.Quit


       'Return message bar to original status
        Application.StatusBar = False
        Application.DisplayStatusBar = oldStatusBar


    Set pvtTable = Worksheets("1. Roll Rate Pivots").Range("C13").PivotTable
    pvtTable.RefreshTable

    Columns("B:B").EntireColumn.AutoFit
    Columns("C:j").Select
    Selection.ColumnWidth = 13

  'Notify user process has completed
  MsgBox ("Update complete")
End Sub

It basically opens a Access dbase, runs a Access macro and closes Access. I have an ODBC connection to the table that is created by the macro in the same excel file that this code is triggered from. I have this running successfully in excel 2007. We recently upgrade office 2013, we started to receive this message. When we debug, it highlights this line of code. At first I though it had something to do with the object library for that version, all the latest one is checked. Has anyone encountered a similar issue. Any help would be greatly appreciated.

appAccess.DoCmd.RunMacro "0_Retrieve_Scrub"

Error message

您是否 100% 确定您引用的宏名称存在于正在打开的数据库中,并且宏名称中的前导 0 不会导致任何问题?

I ran into the exact same error while attempting to run an Access Macro from Excel VBA.

Change this:

appAccess.DoCmd.RunMacro "0_Retrieve_Scrub"  '<-- Error line referring to Access subroutine`

To this:

appAccess.Run "0_Retrieve_Scrub"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM