I am trying to run an excel macro from access 2016. This has a lot of examples out their however they are all old. The exact error code I receive is run-time error '1004':cannot run the macro "TestScript()". The macro may not be available in this workbook or all macros may be displayed. I am only running something easy for the test. I have ensured that macros is enabled in excel. the excel code is as follows Public Sub TestScript() MsgBox "IT WORKED" End SubReal simple for the test. Access is opening the excel spreadsheet however it stops there with an error code.My Access code is very simple and is below. I have also noted where the code stops. While I am new at VBA I have done a lot of research in this. I am testing as simple code as I could figure out. Any help would be welcomed.Option Compare DatabaseFunction runExcelmacro() Dim XL As Object Set XL = CreateObject("Excel.Application") With XL 'Turn Off warnings .Visible = False .displayalerts = False 'WorkBook path such as "C:\Computer\WorkBook.xlsx" .Workbooks.Open "C:\DATABASE\BLQ-10\Import Database BLQ 10\NTIRAINSTALLTO.xlsm" 'Run the Macro in excel getworkbook .Run TestScript 'Code stops here! 'Close Workbook .ActiveWorkbook.Close (True) .Quite End With Set XL = NothingEnd FunctionPublic Sub runMacroSub() Call runExcelmacro("C:\DATABASE\BLQ-10\Import Database BLQ 10\NTIRAINSTALLTO.xlsm", "TestScript")End Sub 解决方案 I guess OP did not put the code of Testscript in an extra module. Instead the code was put into the class module of the workbook or a worksheet. In the latter case you have to add the workbook or worksheet name in front of the name of the script.Either it is `.Run "ThisWorkbook.TestScript"or in case it is in Sheet1 (codename of the sheet!) .Run "Sheet1.TestScript"Do not forget the quotation marks!PS The OP's code above is working if you put testscript into a module and add quotation marks. .Run "TestScript"Here is a description how to create a module and add code 这篇关于从VBA中的Access宏运行Excel宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!