I am trying to run a script that opens an excel file and executes several macros within the file and closes said file. The script runs exactly as expected when I run it from the command prompt manually.
However, when I schedule the a task to run the script, the script is executed up to the final stage and I get a pop up msg in Excel that reads “Server execution failed”.
Here are some of the things I’ve tried, all have yielded the same Excel error message:
- Schedule the task to run the vbs script using cscript.exe
- Schedule the task to run vbs script directly from cmd
- Set up a bat script to run the vbs script via cmd prompt
- Tried running 32bit and 64bit on each version
- I’ve put all the files and scripts in the same folder and tried all of the previous three
- I’ve played with the various settings on the task scheduler to run when I am logged on/off; computer awake etc.
- Customized configuration permissions via dcomcnfg and gave the user (me) “full control”
- Dropped “Authentication Level” to “None”
Other details:
- I am using Windows 10 64bit and Office 10
- The Excel file itself is saved as an xlsb file w/size 8,741 KB
- I have three other jobs that are similar to this one and all of them run without any issues
- I have admin rights on my machine
- The script is being run as me (i.e., using my profile/account)
This is the vbs script, "macro launcher" (originally sourced from here):
'Input Excel File's Full Path
ExcelFilePath = "C:\Users\person\Desktop\script\filewithmacros.xlsb"'Input Module/Macro name within the Excel File
MacroPath1 = "Module2.LoadAddins"
MacroPath2 = "Module4.ForceCalc"
MacroPath3 = "Module1.SendPDF"'Create an instance of Excel
Set ExcelApp = CreateObject("Excel.Application")
'Do you want this Excel instance to be visible?
ExcelApp.Visible = True 'or "False"'Prevent any App Launch Alerts (ie Update External Links)
ExcelApp.DisplayAlerts = TRUE
'Open Excel File
Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)
'Execute Macro Code 1
ExcelApp.Run MacroPath1
'Force Calculation
ExcelApp.Calculate
'Execute Macro Code 2
ExcelApp.Run MacroPath2
'For a wait for calc to finish
WScript.Sleep 180000
'Execute Macro Code 3
ExcelApp.Run MacroPath3
'Reset Display Alerts Before Closing
ExcelApp.DisplayAlerts = True
'Save Excel File (if applicable)
wb.Save
'Close Excel File
wb.Close
'End instance of Excel
ExcelApp.Quit
'Leaves an onscreen message!
MsgBox "Your Automated Task successfully ran at "& TimeValue(Now), vbInformation
This script runs perfectly when we run it directly from the command prompt as
However, when we schedule the task to run a bat containing the same code (shown below), we get an excel error: "Server execution failed"
cd c:\windows\SysWOW64 C:\Windows\SysWOW64\cscript.exe C:\Users\name\Desktop\script\MacroLauncher.vbs
The user account for the task is mine (admin rights) and I have tried both run only when logged on only/logged on or not options and both fail
the add argument is
/c "C:\Users\name\Desktop\script\scriptfilename.bat"