Task Scheduler fail to open excel and run macros

RoeyJia

New Member
Joined
Jan 25, 2023
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Hi, I am facing problem for Task Scheduler to run a excel macros. When I run the Vbscript 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.
problem.png
problem2.png

My VBS:
'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"

My last 4 lines of VBA:
Sheets("Monthly PM").Delete
ActiveWorkbook.Save
Application.Quit
End Function
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top