Forum Discussion

Roey_Jia's avatar
Roey_Jia
Copper Contributor
Jan 25, 2023

Task Scheduler fail to open excel and run the macros

Hi, I am facing problem for Task Scheduler to run a excel macros. When I run in Task Scheduler, the status shows running but nothing happen. I open the excel file manually and it shows below reasons, so i have to end the excel using task manager to let me access to the file again.

 

Microsoft Excel cannot access the file "" There are several possible reasons:

-The file name or path does not exist.

-The file is being used by another program.

-The workbook you are trying to save has the same name as a currently open workbook.

 

My VBscript:

'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\roeyj\OneDrive\Desktop\Intern\Monthly PM\Service Contracts as of 2022 (macro).xlsm"
Set iWb = objExcelApp.Workbooks.Open(sFilePathXlsm)

'1. Run 1st Macro in another Excel
objExcelApp.Run "'" & iWb.Name & "'!Sheet3.contract_vba"

 

'Save & Close file
iWb.Close
iwb.Save
objExcelApp.DisplayAlerts = True
objExcelApp.Quit
objExcelApp.Run "'" & iWb.Name & "'!Sheet3.contract_vba"

No RepliesBe the first to reply

Resources