Home » excel » vba – Fixing "Unknown runtime error" code 800A03EC in VBScript to run macro without opening Excel

vba – Fixing "Unknown runtime error" code 800A03EC in VBScript to run macro without opening Excel

Posted by: admin May 14, 2020 Leave a comment


I’m trying to create and run a VBScript to run a macro I’ve created (PVT_Paste_Macro.xlsm) on Excel files without opening each individual Excel file (I have 528 files!) Here is my code:

Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Users\Owner\Desktop\PVT_Paste_Macro.xlsm'!Module1.PVT_Paste_Macro"
objExcel.DisplayAlerts = False
Set objExcel = Nothing

After running the code, I get the following error:

Script: C:\Users\Owner\Desktop\VBA for macros - PVT.vbs
Line:   2
Char:   1
Error:  Unknown runtime error
Code:   800A03EC
Source: Microsoft VBScript runtime error

I run the script while the macro file is open. The macro file, the (test) Excel file I’d like to run the macro on, and the VBS script are all located on the Desktop.

Can anyone help? Thanks.

How to&Answers:

The code does not work, because it does not like the fact, that the excel file, containing the code open before the code is executed:

enter image description here

Using your code, try this simple steps and make sure it works:

  1. Created a Script.xlsm file on the Desktop.
  2. Added the following in Modul1:

Sub FromExcel()
    MsgBox "FROM EXCEL"
End Sub
  1. Called it from a Script.vbs like this:

Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Users\UserName\Desktop\Script.xlsm'!Modul1.FromExcel"
objExcel.Visible = True 'Or "False", depending on what you want.
Set objExcel = Nothing
  1. Profit

As a way around, if you want to run the “macro” from an opened Excel file, then something like GetObject would be useful:

Set objExcel = GetObject("C:\Users\UserName\Desktop\xl.xlsm")
objExcel.Application.Run "Modul1.FromExcel"
Set objExcel = Nothing

However, this is probably an XY problem – there should be a better way of doing the whole story, e.g. running the “macro” from a single independent Excel file, which opens the other Excel files in the desktop and processes them, without the need of VBScript. Probably check these: