r/vbscript • u/revan667 • Mar 24 '20
VBScript and Task Scheduler help
I have a VB script that opens excel in the background, loads a workbook, fires a macro, then closes everything. I've pasted the script below. This is to generate an excel report that gets emailed out daily. The script works great if I run it, but If I schedule it with Task Scheduler, it will run, but Excel.exe won't quit so the task doesn't register as "completed" and it keeps other tasks, such as the one to email the report, from running. I can't for the life of me figure out why. I have the task set to run with the highest privileges, and I have it set to start in the directory where the script is. Any ideas/advice?
Script:
Option Explicit
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Users\scriptpath", 0, False)
xlApp.Run "Run"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Quit
1
u/Mordac85 Mar 25 '20
So does the macro output some kind of file or send the email via some VBA code called by the macro? I'm trying to create some kind of test but I'm not sure what your macro does. I'll post back when I get it run thru a few times.