0

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
JackCox94
  • 1
  • 1
  • See [this comment](https://stackoverflow.com/questions/2136768/using-application-run-in-excel-vba-when-workbook-name-contains-spaces#comment87501768_2136823). – user692942 Jan 06 '23 at 17:15
  • Does this answer your question? [VBS with Space in File Path](https://stackoverflow.com/questions/14360599/vbs-with-space-in-file-path) – Zephyr Jan 07 '23 at 09:47

0 Answers0