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
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:
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):
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.
Solved! First I did a Run command and used wscript. Could also use cscript /I as joseph4tw advised but I didn't know about that.
This showed me the error that it couldn't find the VBScript engine. I looked on internet and vbscript.dll should be in Windows/System file for my 98 computer. It was not there. I found the site www.dll-files.com and downloaded the file. Then I rebooted. Then I did a Run command to install it, like this: Run regsvr32 vbscript.dll. It gave a success message and now it works.
I believe this was caused by malware. I can't get the malware off my 98 computer because I can't run any of the newer antivirus.
Because of my new XP computer, I am working on making disk image and using a linux recovery CD. That linux, I think will run on 98 and I hope I can run the antivirus to clean up that computer.
Thanks for everyone's help because it led me to the solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With