I have a very simple VBScript to refresh and save a specified Excel file (see code below). It works fine when you double click the VBS file but I need to schedule it to run automatically using Windows Task Scheduler. I know how to create the task and set one up which works fine but only when "Run only when user is logged on" is selected.
The scheduled task / script does not work if you select "Run whether user is logged on or not". The error I get is "Object Required"
I have other scheduled tasks that run other scripts and BAT files (not Excel refresh ones) that work fine with the run whether user is logged on or not option selected. The only one that has issues is the script to refresh the Excel file.
I leave my account logged in through out the week but the computer automatically reboots on the weekend. Also, what if I am out sick or on vacation? I still want the script to run and refresh the file.
'Set path of Excel File
Dim path, filename, fullpath
path = "\\server\path\"
filename = "File_Name.xlsx"
fullpath = path & filename
' Create an Excel instance
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
' Disable Excel UI elements
oExcel.Visible = False
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False
' Open the specified file and RefreshAll then Save
Set oWorkbook = oExcel.Workbooks.Open(fullpath)
oWorkbook.RefreshAll
oWorkbook.Save
' Close the file
oExcel.Quit
Set oWorkbook = Nothing
Set oExcel = NothingAny ideas how to get this to run even if I am not logged on with the "Run whether user is logged on or not" is selected.
The task is setup on a VM (Win Server 2008) - corp environment - connected to a domain