.bat file doesn't run when started from task scheduler

I have set up a .bat file to open an excel workbook that I need to run at 1:00 AM.  The file is a .xlsm that I am using to generate a report.  I can run the excel file manually and it works.  I created a .vbs file to start the .xlsm file, and it works.  I created a .bat file to run the .vbs file and it works as well.  When I try to run the .bat file from a scheduled task, I can see the task status show running and then completed, but the report is not generated.  I am not sure what the problem could be.

This is the .bat file.

@echo off
cscript "C:\REP_Reports\Report Design\vbScripts\vbsMRT.vbs"

This is vbsMRT.vbs.

option explicit
on error resume next
Dim objExcel
Dim objWorkbook
Dim MyFile
Set objExcel = CreateObject("EXCEL.APPLICATION")
objExcel.visible = true
Set objWorkbook = objExcel.Workbooks.Open("C:\REP_Reports\Report Design\2MARYMO_MRT01R01.xlsm")
Set objWorkbook = Nothing
Set objExcel = Nothing
Aaron GreeneProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
What does your Action look like? Per your post, it should be...

Program/script: cmd
Add arguments: /c c:\folder\file.bat

Try playing with the task General, Security Options:
- "Run only when user is logged on", or "Run whether user is logged on or not".
- Also, set "Run with highest privleges"
Bill PrewIT / Software Engineering ConsultantCommented:
For debugging you can try the following as well:

Program/script: cmd
Add arguments: /c c:\folder\file.bat>"C:\REP_Reports\Report Design\vbScripts\vbsMRT.log" 2>&1

Also remove the "on error resume next" in the VBS script.

Then after you try and run it from the task scheduler check the LOG file for any errors.

Aaron GreeneProgrammerAuthor Commented:
I tried all of your suggestions, and go the same results, nothing.  I deleted my existing task and decided to start over, but this time I used the Create basic task option.  After setting things up, I set it to run on a time schedule.  The task successfully ran.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Bill PrewIT / Software Engineering ConsultantCommented:
Sounds like something was set in the first task that was causing the problem.  Can't really say what that might have been at this point, but glad that recreating it resolved the problem for you, well done.

Aaron GreeneProgrammerAuthor Commented:
Do you know what the difference is between the "Create Task" and "Create Basic Task" options?  Once the task is created, the properties screens are identical.
Bill PrewIT / Software Engineering ConsultantCommented:
Conceptually the difference is just the complexity of the process.  The "Basic" approach uses more of a wizard type approach, leading the user through a simpler set of steps and questions.  The "create task" method takes you right to the screens involved and you have to know a bit more about what you need to enter.

The end result is the same, a scheduled task is added to the system.  But there may be some differences since the basic approach probably defaults some settings that non-basic approach allows the user to change during initial task creation.

Aaron GreeneProgrammerAuthor Commented:
I still don't know what caused the problem.  I'm chalking that up to user error.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.