Search code examples
excelvbavbscriptwindows-task-scheduler

VBS Running Macro Enabled Workbook Error 800A9C68


I'm having a small issue with a VBS script I pieced together from the internet.

Dim xlApp, xlBook


Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("LOCATION", 0, True)


xlapp.Visible = True

xlApp.Run "RefreshAdj"

xlBook.Close False
set xlBook = Nothing

xlApp.Quit
Set xlApp = Nothing

WScript.Echo "Finished."
WScript.Quit

It will run off task scheduler but it always gives this error.

Line: 11
Char: 1
Error: Unknown runtime Error
Code: 800A9C68
Source: Microsoft VBScript runtime Error

Its not that big of a deal, but slightly annoying because it will not run the next day until someone clears the dialog box for this error.


Solution

  • I've just had the same problem in a script where I updated the data in a sheet, saved the file with a different name and then did

    ActiveWorkbook.Close
    

    I think the problem is that by saving the file with a different name somehow Excel gets confused as to what the ActiveWorkbook is. I had the same error with ThisWorkbook.