每当我尝试执行以下代码时,都会收到以下消息。
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
它基本上打开Access dbase,运行Access宏并关闭Access。我有一个ODBC连接到由该宏驱动此代码的同一个excel文件中的宏创建的表。我已经在excel 2007中成功运行了。我们最近升级了Office 2013,我们开始收到此消息。当我们调试时,它会突出显示这行代码。起初我虽然它与该版本的对象库有关,但是检查了所有最新版本。有没有人遇到类似的问题。任何帮助将不胜感激。
appAccess.DoCmd.RunMacro“0_Retrieve_Scrub”
答案 0 :(得分:0)
您是否100%确定您所引用的宏名称存在于正在打开的数据库中,并且宏名称中的前导0不会导致任何问题?
答案 1 :(得分:0)
我在尝试从 Excel VBA 运行 Access 宏时遇到了完全相同的错误。
改变这个:
appAccess.DoCmd.RunMacro "0_Retrieve_Scrub" '<-- Error line referring to Access subroutine`
为此:
appAccess.Run "0_Retrieve_Scrub"