I have an Excel VBA macro that updates the Excel file, basically sweeping through the records to identify if certain new employees have had training at various points before they reach 90 days, and if not, blasts out emails to distribution groups as a reminder. I would like to have this macro run automatically once a day so my computer will sweep through the file and launch emails when the specific milestone date arises for each record.
The Excel macro runs perfectly. When I manually run the VBS file, it runs perfectly.
When I try to run (manually or scheduled) from Task Scheduler, the log shows it completes but it doesn't run the macro.
I have tried using both the "Run only when user is logged on" and "Run whether user is logged on or not" and both have the same result. My user account (Bachenheimere) is showing as the one to use for running the task, so I obviously have rights to run the file.
For the Task scheduler, I am using Action: Start a Program
Program Script: "C:\Windows\SysWOW64\cscript.exe"
Add arguments: "C:\Users\Bachenheimere\RunExcelMacroForCoachTracking.vbs"
Again, the Task Scheduler log shows it successfully completes in about 1.5 minutes (when I run manually it completes in about 15-20 seconds). I would prefer not to run the VBS file manually each day.
Here is the VBS file code:
Dim xlApp, xlBook
Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Users\Bachenheimere\file.txt",2,true)
Set xlApp = CreateObject("Excel.Application")
objFileToWrite.WriteLine(FormatDateTime(Now) & "Create Excel Object")
xlApp.Application.Visible = True
objFileToWrite.WriteLine(FormatDateTime(Now) & "App Visible = True")
xlApp.DisplayAlerts = False
objFileToWrite.WriteLine(FormatDateTime(Now) & "Display ALerts = False")
Set xlBook = xlApp.Workbooks.Open("H:\EmCare\Clinical Services\Provider Coaching\NEOU Tracking\Coach Trackingv3.xlsm", 0, True)
objFileToWrite.WriteLine(FormatDateTime(Now) & "Excel book opened")
xlApp.Run "Sheet1.SendReminderMail"
objFileToWrite.WriteLine(FormatDateTime(Now) & "Macro is run")
xlBook.Save
objFileToWrite.WriteLine(FormatDateTime(Now) & "Macro is saved")
xlBook.Close
objFileToWrite.WriteLine(FormatDateTime(Now) & "Book closed")
xlApp.Quit
objFileToWrite.WriteLine(FormatDateTime(Now) & "App Quit")
objFileToWrite.Close
Set objFileToWrite = Nothing
set xlBook = Nothing
Set xlApp = Nothing
WScript.Echo "Your Automated Task successfully ran at " & TimeValue(Now)
WScript.Quit