Start excel from Task Scheduler was working, now fails
excel, scheduled-tasks, vba, vbscript, wsh
Solution
I'm going to take a wild guess here.
"It works when I run the cscript but not when the Task runs it" makes me think this is a permissions issue. When you setup a Windows Scheduled Task, you should be able to set it to run as a specific user (and also set whether to run if the user is not logged in). I'm not sure about Win 98, but can you find out what the Task properties say? When you run the code yourself, your permissions are used and the scheduled task might be using a user who doesn't have the permissions to run it.
How can this happen if you didn't change anything? The only thing I can think of is that either:
- The user that the scheduled task uses no longer exists or the permissions have changed
- The user had a password expiration date and it has recently passed
- If the scheduled task is using your username, did you save the password in the Task properties and then recently change your password, but did not update the scheduled task's password?
Also, some anti-virus products stop the use of some vbscripts. Did you possibly install anything new right before it stopped working?
To check to see where the error might be coming from (hoping this works since I'm not very familiar with Win98 machines):
- Find out which user is set to run the scheduled task
- Start Command Prompt as another user (I think it's Shift+Right-Click --> Run as... [note, I don't know about Windows 98 so I'm crossing my fingers that you can do this])
- Run the cscript from the command prompt: `C:\>cscript <dir>\myscript.extension \I` (note, the `\I` is Interactive mode, which should show errors (see here for more info)
I really hope this helps. I would have put this in a comment, but it's too much text.
Problem
I've been running my excel 2000 vba program with Task Scheduler and cscript and vbscript for about a year now. A few days ago it stopped working. I can run the program manually. Whenever Task Scheduler starts it, the black window displays for about 1-2 seconds then closes. I've tried commenting out error handling but I always get the same results. I tried showing `MsgBoxes` but results are still the same. I found on your forum here, an easier way to do it and I tried that with the same results. So what do I need to do to debug this? Here is code I tried from this forum: ``` Option Explicit Dim xlApp, xlBook Set xlApp = CreateObject("Excel.Application") '~~> Change Path here Set xlBook = xlApp.Workbooks.Open("C:\My Documents\___Stocksfilter.xls", 0, True) xlApp.Run "A_Pick" xlBook.Close xlApp.Quit Set xlBook = Nothing Set xlApp = Nothing WScript.Echo "Finished." WScript.Quit ``` Here is code I've been using: ``` 'Script to start my filter.xls program with named macro 'MsgBox "In RunExcel" ' Create an Excel instance Dim myExcelWorker Set myExcelWorker = CreateObject("Excel.Application") ' Disable Excel UI elements myExcelWorker.DisplayAlerts = False myExcelWorker.AskToUpdateLinks = False myExcelWorker.AlertBeforeOverwriting = False myExcelWorker.FeatureInstall = msoFeatureInstallNone ' Open the Workbook Dim oWorkBook Dim strWorkerWB strWorkerWB = "C:\My Documents\___Stocks\filter.xls" 'MsgBox "Opening filter" on error resume next Set oWorkBook = myExcelWorker.Workbooks.Open(strWorkerWB) if err.number <> 0 Then ' Error occurred - just close it down. MsgBox "open Error occurred" End If err.clear on error goto 0 'MsgBox "Running macro" Dim strMacroName strMacroName = "A_Pick" on error resume next ' Run the macro myExcelWorker.Run strMacroName if err.number <> 0 Then ' Error occurred - just close it down. MsgBox "run macro Error occurred" End If err.clear on error goto 0 ' Clean up and shut down Set oWorkBook = Nothing myExcelWorker.Quit Set myExcelWorker = Nothing Set WshShell = Nothing ```