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

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

问题描述

我有一个通过Task Scheduler执行的脚本文件,该文件在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.

推荐答案

从任务计划程序或以登录脚本(gpedit.msc►用户配置►Windows设置►脚本(登录/注销))执行.VBS显式引用开销可执行文件.对于基于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天全站免登陆