vbscript 通过任务计划程序在 Windows 10 中打开 excel 文件 [英] vbscript to open an excel file in Windows 10 via Task Scheduler

查看:63
本文介绍了vbscript 通过任务计划程序在 Windows 10 中打开 excel 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过任务计划程序执行的脚本文件,该文件在 Windows 7 中运行良好,但在 Windows 10 中无法运行.

I have a script file that I'm executing via Task Scheduler that worked fine in Windows 7, and is not working in Windows 10.

代码片段如下:

Dim myxlApplication, myWorkBook

Set myxlApplication = CreateObject("Excel.Application")
myxlApplication.Visible = False
Set myWorkBook = myxlApplication.Workbooks.Open( emlAttach )
myxlApplication.DisplayAlerts = False
myWorkBook.Application.Run "Main.Main" 
myxlApplication.DisplayAlerts = True
myxlApplication.Quit
Set myxlApplication = Nothing

emlAttach 在脚本前面设置为绝对路径和带扩展名的文件名.

emlAttach is set earlier in the script to the absolute path and filename with extension.

通过单击脚本文件执行此操作时,它可以完美运行.当它作为计划任务运行或强制从任务计划程序运行时,它会询问我想使用什么程序来打开文件.如果我选择 Excel,它会给我一个错误,告诉我该文件不存在.

When executing this via clicking on the script file, it works perfectly. When running it as a scheduled task, or forcing a run from task scheduler, it asks me what program I'd like to use to open the file. If I select Excel, it gives me an error telling me that the file doesn't exist.

该错误的文件扩展名是错误的,xlsx 与变量 xlsb 限定的内容相比.

The file extension on that error is wrong, xlsx vs what is qualified by the variable xlsb.

推荐答案

从任务计划程序执行 .VBS 或作为登录脚本(gpedit.msc ► 用户配置 ► Windows 设置 ► 脚本(登录/注销))将需要显式引用开销可执行文件.这将是 WSCRIPT.EXE 用于基于窗口的返回或 CSCRIPT.EXE 用于基于控制台的返回.此外,如果 .VBS 默认与 WSCRIPT.EXE 关联,您可能需要将 CSCRIPT.EXE 指定为正在运行的进程以避免基于 Windows 的返回.

Executing a .VBS from the Task Scheduler or as a login script (gpedit.msc ► user Configuration ► Windows Settings ► Scripts (Logon/Logoff)) will require explicit reference to the overhead executable. This would be WSCRIPT.EXE for a windows based return or CSCRIPT.EXE for a console based return. Further, if the .VBS is associated by default with WSCRIPT.EXE, you may need to specify CSCRIPT.EXE as the running process in order to avoid a windows based return.

CSCRIPT.EXE c:<path to vbs script file>myScript.vbs

在 CMD 提示符下测试命令行.如果文件夹名称包含空格,您可能需要用引号将其括起来.

Test the command line at a CMD prompt. You may need to enclose folder names in quotes if they contain spaces.

这篇关于vbscript 通过任务计划程序在 Windows 10 中打开 excel 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆