I am trying to execute an Excel VBA macro with a VBScript so that I can run it with cscript
in batch. When I run it in Excel it works fine, but when I call the VBScript I get a permission error saying that create object is the cause.
I have tried rewriting the VBScript to no avail and it only works in Excel.
But the one that seems to be the most promising is below:
Option Explicit
On Error Resume Next
Sub ExcelMacro()
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\MyWorkbook.xls", 0, True)
xlApp.Run "MyMacro"
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
The problem is that when I run it in the batch file, it shows that Windows starts to run it but then I get an error saying
Microsoft VBS runtime error: Permission denied Create Object.
How can I fix this?