Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start excel from Task Scheduler was working, now fails

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
like image 507
RoseAb Avatar asked Mar 09 '13 00:03

RoseAb


2 Answers

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:

  1. The user that the scheduled task uses no longer exists or the permissions have changed
  2. The user had a password expiration date and it has recently passed
  3. 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):

  1. Find out which user is set to run the scheduled task
  2. 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])
  3. 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.

like image 158
Joseph Avatar answered Nov 18 '22 17:11

Joseph


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.

like image 37
RoseAb Avatar answered Nov 18 '22 16:11

RoseAb