2

这是我试图实现的事件序列: 计划任务 - 每天同时运行并启动 VBScript VBScript 启动 Excel 工作簿并运行宏。这是片段-

Set xlApp = CreateObject ("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open (xlFilePath,0,False)
xlApp.Run "Main"

现在的问题是,如果我手动运行任务,它运行良好。当我未登录到服务器时运行计划任务时,它不会启动 excel。当没有用户登录时,我必须在上面的代码中进行哪些更改才能启动 excel?我已将 Excel 宏安全性设置为低。

Excel 2003 和 Windows Server2003 64

4

3 回答 3

5

Take a look at MS Knowledge Base - according to this, Office apps need an UI to run.

Thus, try using any user but the system user:

For example, code that is started by Task Scheduler under the SYSTEM account runs in the same environment as "server-side" ASP code or as DCOM code. Therefore, many of the issues that this article describes may occur.

Also, try to call Main from the Workbook_Open event in the Excel file instead of xlApp.Run "Main"...

于 2012-12-03T21:04:33.313 回答
3

不确定它是否已经解决,但我遇到了问题并通过以下步骤解决。

创建以下文件夹

(32 位,始终)C:\Windows\System32\config\systemprofile\Desktop

(64Bit) 以上文件夹和 C:\Windows\SysWOW64\config\systemprofile\Desktop

如果您使用系统帐户运行,这将解决问题。

于 2016-03-07T18:27:47.080 回答
0

You should be able to set an option to use a username when running the task as well as have the task run whether the user is logged on or not. Here's an example from Windows Server 2008:

enter image description here

于 2012-12-03T19:58:39.420 回答