Good evening. I'm trying to schedule an excel macro through task scheduler. I've got the below code written for opening the excel file and running the code however it's kicking out an error when it's hitting the Application.Run step.
Does anyone have any ideas where i'm going wrong?
On Error Resume Next
Set oFSO = CreateObject("Scripting.FileSystemObject")
set oFile = oFSO.CreateTextFile("c:\scripts\log.txt")
Set oExcel = WScript.CreateObject("Excel.Application")
If oFSO.FileExist("C:\scripts\Excel Files\my_excel_file.xlsm") then
oFile.WriteLine "File Exists"
oExcel.Application.Run "'C:\scripts\Excel Files\my_excel_file.xlsm'!RefreshAll"
if err.number <> 0 then
oFile.WriteLine "error = " & err.number & " " & err.description
end if
Else
oFile.WriteLine "File does not exist"
End If
oExcel.Application.close
I originally had the file on a network drive which I thought would be the issue so i've moved it to the C: Drive on a remote desktop to try and counter that issue.
I initially thought it was a task scheduler issue, however the log is being filled out which tells me there's something else going on. I've set up the action as the attached image.