任务计划程序和VBScript刷新Excel文件的问题 [英] Problem with Task Scheduler and VBScript to Refresh an Excel File

查看:116
本文介绍了任务计划程序和VBScript刷新Excel文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的VBScript来刷新和保存指定的Excel文件(参见下面的代码)。双击VBS文件时它工作正常但我需要安排它使用Windows任务计划程序自动运行。我知道如何创建任务并设置
一个可以正常工作,但仅限于"仅在用户登录时运行"时已选中。

I have a very simple VBScript to refresh and save a specified Excel file (see code below). It works fine when you double click the VBS file but I need to schedule it to run automatically using Windows Task Scheduler. I know how to create the task and set one up which works fine but only when "Run only when user is logged on" is selected.

如果选择"运行用户是否登录",则计划任务/脚本不起作用。我得到的错误是"对象必需"

The scheduled task / script does not work if you select "Run whether user is logged on or not". The error I get is "Object Required"

我有其他运行其他脚本和BAT文件(而不是Excel刷新文件)的计划任务,无论用户是否登录,都可以正常运行是否选择了选项。唯一有问题的是刷新Excel文件的脚本。

I have other scheduled tasks that run other scripts and BAT files (not Excel refresh ones) that work fine with the run whether user is logged on or not option selected. The only one that has issues is the script to refresh the Excel file.

我让我的帐户在一周内登录,但计算机会在周末自动重启。此外,如果我生病或度假怎么办?我仍然希望脚本运行并刷新文件。

I leave my account logged in through out the week but the computer automatically reboots on the weekend. Also, what if I am out sick or on vacation? I still want the script to run and refresh the file.

'Set path of Excel File
   Dim path, filename, fullpath
   path = "\\server\path\"
   filename = "File_Name.xlsx"
   fullpath = path & filename
' Create an Excel instance
   Dim oExcel
   Set oExcel = CreateObject("Excel.Application") 
 ' Disable Excel UI elements
   oExcel.Visible = False
   oExcel.DisplayAlerts = False
   oExcel.AskToUpdateLinks = False
   oExcel.AlertBeforeOverwriting = False
 ' Open the specified file and RefreshAll then Save
   Set oWorkbook = oExcel.Workbooks.Open(fullpath)
   oWorkbook.RefreshAll
   oWorkbook.Save
 ' Close the file
   oExcel.Quit
   Set oWorkbook = Nothing
   Set oExcel = Nothing

即使我没有使用"运行是否登录用户"登录,任何想法如何使其运行已选中。

Any ideas how to get this to run even if I am not logged on with the "Run whether user is logged on or not" is selected.

任务在VM(Win Server 2008)上建立 - 公司环境 - 连接到域

The task is setup on a VM (Win Server 2008) - corp environment - connected to a domain

推荐答案

即使我没有使用"运行是否记录用户"登录,任何想法如何运行是否"已选中。

Any ideas how to get this to run even if I am not logged on with the "Run whether user is logged on or not" is selected.


这是因为MS Office产品需要交互式会话才能正常运行。

This happens because MS Office products require an interactive session to run properly.


这篇关于任务计划程序和VBScript刷新Excel文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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