从任务调度器开始excel工作,现在失败了。

时间:2023-01-19 10:45:18

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.

我已经使用任务调度程序、cscript和vbscript运行我的excel 2000 vba程序大约一年了。几天前它停止工作了。我可以手动运行程序。每当任务调度程序启动时,黑色窗口显示大约1-2秒,然后关闭。

I've tried commenting out error handling but I always get the same results. I tried showing MsgBoxes but results are still the same.

我尝试过注释掉错误处理,但是得到的结果总是一样的。我试着显示msgbox,但是结果还是一样的。

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

2 个解决方案

#1


2  

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.

“当我运行cscript时,它是有效的,但当任务运行时,它不会”让我认为这是一个权限问题。当您设置一个Windows计划任务时,您应该能够将它设置为以特定用户的身份运行(如果用户没有登录,也可以设置是否运行)。我不确定赢98,但你能找出任务属性说什么吗?当您自己运行代码时,将使用您的权限,计划的任务可能使用的用户没有运行该代码的权限。

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. 计划任务使用的用户不再存在,或者权限已经更改
  3. The user had a password expiration date and it has recently passed
  4. 用户有一个密码过期日期,它最近已经通过了
  5. 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?
  6. 如果计划任务使用的是您的用户名,您是否在任务属性中保存了密码,然后最近更改了密码,但没有更新计划任务的密码?

Also, some anti-virus products stop the use of some vbscripts. Did you possibly install anything new right before it stopped working?

此外,一些反病毒产品停止使用一些vbscripts。在它停止工作之前,你是否可能安装了任何新的东西?

To check to see where the error might be coming from (hoping this works since I'm not very familiar with Win98 machines):

检查错误可能来自哪里(由于我对Win98机器不是很熟悉,所以希望它能工作):

  1. Find out which user is set to run the scheduled task
  2. 找出哪个用户被设置为运行计划任务
  3. 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])
  4. 作为另一个用户启动命令提示符(我认为它是Shift+右击——>作为…(注意,我不知道Windows 98,所以我祈祷你能做到)
  5. 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)
  6. 从命令提示符:C:\>cscript \myscript >运行cscript。扩展\I(注意,\I是交互模式,应该显示错误(请参阅此处了解更多信息)

I really hope this helps. I would have put this in a comment, but it's too much text.

我真的希望这能有所帮助。我本想把这个写在评论里,但是文字太多了。

#2


2  

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.

解决了!首先,我执行了Run命令并使用了wscript。也可以使用cscript /我作为joseph4tw的建议,但我不知道。

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.

这显示了它找不到VBScript引擎的错误。我浏览了互联网和vbscript。dll应该在我的98计算机的Windows/System文件中。这是不存在的。我找到了网站www.dll-files.com并下载了这个文件。然后重启。然后我执行了一个Run命令来安装它,如下所示:Run regsvr32 vbscript.dll。它传递了一个成功的信息,现在它起作用了。

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.

我相信这是恶意软件造成的。我不能从我的98电脑上清除恶意软件,因为我不能运行任何更新的杀毒软件。

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.

由于我的新XP电脑,我正致力于制作磁盘映像和使用linux恢复CD。

Thanks for everyone's help because it led me to the solution.

谢谢大家的帮助,因为这让我找到了解决办法。

#1


2  

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.

“当我运行cscript时,它是有效的,但当任务运行时,它不会”让我认为这是一个权限问题。当您设置一个Windows计划任务时,您应该能够将它设置为以特定用户的身份运行(如果用户没有登录,也可以设置是否运行)。我不确定赢98,但你能找出任务属性说什么吗?当您自己运行代码时,将使用您的权限,计划的任务可能使用的用户没有运行该代码的权限。

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. 计划任务使用的用户不再存在,或者权限已经更改
  3. The user had a password expiration date and it has recently passed
  4. 用户有一个密码过期日期,它最近已经通过了
  5. 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?
  6. 如果计划任务使用的是您的用户名,您是否在任务属性中保存了密码,然后最近更改了密码,但没有更新计划任务的密码?

Also, some anti-virus products stop the use of some vbscripts. Did you possibly install anything new right before it stopped working?

此外,一些反病毒产品停止使用一些vbscripts。在它停止工作之前,你是否可能安装了任何新的东西?

To check to see where the error might be coming from (hoping this works since I'm not very familiar with Win98 machines):

检查错误可能来自哪里(由于我对Win98机器不是很熟悉,所以希望它能工作):

  1. Find out which user is set to run the scheduled task
  2. 找出哪个用户被设置为运行计划任务
  3. 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])
  4. 作为另一个用户启动命令提示符(我认为它是Shift+右击——>作为…(注意,我不知道Windows 98,所以我祈祷你能做到)
  5. 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)
  6. 从命令提示符:C:\>cscript \myscript >运行cscript。扩展\I(注意,\I是交互模式,应该显示错误(请参阅此处了解更多信息)

I really hope this helps. I would have put this in a comment, but it's too much text.

我真的希望这能有所帮助。我本想把这个写在评论里,但是文字太多了。

#2


2  

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.

解决了!首先,我执行了Run命令并使用了wscript。也可以使用cscript /我作为joseph4tw的建议,但我不知道。

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.

这显示了它找不到VBScript引擎的错误。我浏览了互联网和vbscript。dll应该在我的98计算机的Windows/System文件中。这是不存在的。我找到了网站www.dll-files.com并下载了这个文件。然后重启。然后我执行了一个Run命令来安装它,如下所示:Run regsvr32 vbscript.dll。它传递了一个成功的信息,现在它起作用了。

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.

我相信这是恶意软件造成的。我不能从我的98电脑上清除恶意软件,因为我不能运行任何更新的杀毒软件。

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.

由于我的新XP电脑,我正致力于制作磁盘映像和使用linux恢复CD。

Thanks for everyone's help because it led me to the solution.

谢谢大家的帮助,因为这让我找到了解决办法。