• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Task Scheduler fail to open excel and run macros

RoeyJia

New Member
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. My Macros is to auto send email monthly through outlook.

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"

[/QUOTE]


My Excel file is attached below
 

Attachments

  • problem.png
    problem.png
    16.2 KB · Views: 5
  • problem2.png
    problem2.png
    13.1 KB · Views: 5
  • Service Contracts as of 2022 (macro).xlsm
    794 KB · Views: 1
Last edited:
Hi, where your logic fails is you close a workbook first then you try to save it ! As it should be saving first …​
According to Workbook.Close VBA help it can be achieved with a single codeline rather than two with its parameter as True.​
 
Back
Top