I just got a new work laptop, moving from Excel 2016 to Office 365). I had created a dashboard file on my old laptop that had 2 macros in it.
Refresh - this macro refreshed the two Power Query Tables
UpdateQuarter - this macro refreshed the pivot tables in the file based on the quarter
I had created a .vbs file that would Open the Excel file and run the two macros, then save and close the file. I used Tas Scheduler to have the .vbs file run every hour.
On my old laptop, this worked perfectly and with no issues.
On my new laptop, the Task Scheduler fails on this. I tried double clicking on the .vbs file to just run the script manually. When I do, it launches the Excel file, but gives me the following error message:
Run-time error '91':
Object variable With block variable not set.
When I click on Debug, it highlights this:
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
I can go into the Excel file myself and manually run the macros and they run just fine. I am running everything under myself. I have even tried copying the file and just moving it to my C Drive and updating the file path to that and still get the message.
Here is the .vbs file:
objExcelApp.Quit
Refresh - this macro refreshed the two Power Query Tables
UpdateQuarter - this macro refreshed the pivot tables in the file based on the quarter
I had created a .vbs file that would Open the Excel file and run the two macros, then save and close the file. I used Tas Scheduler to have the .vbs file run every hour.
On my old laptop, this worked perfectly and with no issues.
On my new laptop, the Task Scheduler fails on this. I tried double clicking on the .vbs file to just run the script manually. When I do, it launches the Excel file, but gives me the following error message:
Run-time error '91':
Object variable With block variable not set.
When I click on Debug, it highlights this:
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
I can go into the Excel file myself and manually run the macros and they run just fine. I am running everything under myself. I have even tried copying the file and just moving it to my C Drive and updating the file path to that and still get the message.
Here is the .vbs file:
VBA Code:
'Create Excel App Instance & Open Xlsm File
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = True
objExcelApp.DisplayAlerts = False
'Define Macro File & Path
sFilePathXlsm = "C:\Users\jbohl\OneDrive - Quadient\Central District\2024 Payroll Files\Test Files\Dashboard.xlsm"
Set iWb =
[URL='https://objexcelapp.workbooks.open/']objExcelApp.Workbooks.Open[/URL](sFilePathXlsm)
'1. Run 1st Macro in another Excel
sMacroToRun = "'" & sFilePathXlsm & "'!Refresh"
[URL='https://objexcelapp.run/']objExcelApp.Run[/URL] sMacroToRun
'2. Run 2nd Macro in same file
sMacroToRun = "'" & sFilePathXlsm & "'!UpdateQuarter"
[URL='https://objexcelapp.run/']objExcelApp.Run[/URL] sMacroToRun
'Save & Close file
[URL='https://iwb.save/']iWb.Save[/URL]
iWb.Close
objExcelApp.DisplayAlerts = True
objExcelApp.Quit