Windows任务计划程序 - 打开Excel文件“您想如何打开此文件”

时间:2021-05-10 02:30:10

I'm trying to set up a basic task in the Windows Task Scheduler that opens an Excel file every day. I've done this successfully in the past, but for some reason on the Windows Server 2012 OS I'm using when I try to open the file I get prompted with how do you want to open this type of file?

我正在尝试在Windows任务计划程序中设置一个基本任务,每天打开一个Excel文件。我在过去成功完成了这项工作,但出于某些原因我在尝试打开文件时使用的Windows Server 2012操作系统上出现了提示您打算如何打开此类文件?

Windows任务计划程序 - 打开Excel文件“您想如何打开此文件”

Is there a way to automatically select Excel as the program used to run the file for this task?

有没有办法自动选择Excel作为用于运行此任务的文件的程序?

3 个解决方案

#1


4  

You need to specify the Full path to the Excel.exe application executable as well as the workbook to open.

您需要指定Excel.exe应用程序可执行文件的完整路径以及要打开的工作簿。

Location of Office Programs (64-bit Office on 64-bit Windows Server 2012)

Office程序的位置(64位Windows Server 2012上的64位Office)

  • Microsoft Office 2013
           "%PROGRAMFILES%\Microsoft Office\Office15\EXCEL.EXE"
  • Microsoft Office 2013“%PROGRAMFILES%\ Microsoft Office \ Office15 \ EXCEL.EXE”

  • Microsoft Office 2010
           "%PROGRAMFILES%\Microsoft Office\Office14\EXCEL.EXE"
  • Microsoft Office 2010“%PROGRAMFILES%\ Microsoft Office \ Office14 \ EXCEL.EXE”

  • Microsoft Office 2007
           "%PROGRAMFILES%\Microsoft Office\Office12\EXCEL.EXE"
  • Microsoft Office 2007“%PROGRAMFILES%\ Microsoft Office \ Office12 \ EXCEL.EXE”

  • Microsoft Office 2003
           "%PROGRAMFILES%\Microsoft Office\Office11\EXCEL.EXE"
  • Microsoft Office 2003“%PROGRAMFILES%\ Microsoft Office \ Office11 \ EXCEL.EXE”

  • Microsoft Word 2002
           "%PROGRAMFILES%\Microsoft Office\Office10\EXCEL.EXE"
  • Microsoft Word 2002“%PROGRAMFILES%\ Microsoft Office \ Office10 \ EXCEL.EXE”

  • Microsoft Word 2000
           "%PROGRAMFILES%\Microsoft Office\Office\EXCEL.EXE"
  • Microsoft Word 2000“%PROGRAMFILES%\ Microsoft Office \ Office \ EXCEL.EXE”

For a 32-bit Office version on a 64-bit operating system substitute %PROGRAMFILES(x86)% for %PROGRAMFILES%.

对于64位操作系统上的32位Office版本,将%PROGRAMFILES(x86)%替换为%PROGRAMFILES%。

Example of command line:

命令行示例:

"%PROGRAMFILES%\Microsoft Office\Office14\EXCEL.EXE" "C:\Users\user\Documents\MyWorkbook.xlsx"

Additional command lines options are available to open as read only, etc. See Command-line switches for Excel.

其他命令行选项可以打开为只读等。请参阅Excel的命令行开关。

#2


1  

Three important steps - How to Task Schedule an excel.xls(m) file

三个重要步骤 - 如何任务计划excel.xls(m)文件

simply:

  1. make sure the .vbs file is correct
  2. 确保.vbs文件正确无误

  3. set the Action tab correctly in Task Scheduler
  4. 在任务计划程序中正确设置“操作”选项卡

  5. don't turn on "Run whether user is logged on or not"
  6. 不要打开“运行用户是否登录”

IN MORE DETAIL...

更详细......

Here is an example .vbs file:

这是一个示例.vbs文件:

'
'   a .vbs file is just a text file containing visual basic code that has the extension renamed from .txt  to .vbs

 'Write Excel.xls  Sheet's full path here
 strPath = "C:\RodsData.xlsm" 

'Write the macro name - could try including module name
strMacro = "Update" '    "Sheet1.Macro2" 

'Create an Excel instance and set visibility of the instance
Set objApp = CreateObject("Excel.Application") 
objApp.Visible = True   '   or False 

'Open workbook; Run Macro; Save Workbook with changes; Close; Quit Excel
Set wbToRun = objApp.Workbooks.Open(strPath) 
objApp.Run strMacro     '   wbToRun.Name & "!" & strMacro 
wbToRun.Save 
wbToRun.Close 
objApp.Quit 

'Leaves an onscreen message!
MsgBox strPath & " " & strMacro & " macro and .vbs successfully completed!",         vbInformation 
'

In the Action tab (Task Scheduler):

在“操作”选项卡(任务计划程序)中:

set Program/script: = C:\Windows\System32\cscript.exe

set Program / script:= C:\ Windows \ System32 \ cscript.exe

set Add arguments (optional): = C:\MyVbsFile.vbs

set添加参数(可选):= C:\ MyVbsFile.vbs

Finally, don't turn on "Run whether user is logged on or not".

最后,不要打开“运行用户是否登录”。

That should work.

这应该工作。

Many people also need the following two folders created on their machine:

许多人还需要在他们的机器上创建以下两个文件夹:

32Bit:

C:\Windows\System32\config\systemprofile\Desktop

64Bit:

C:\Windows\SysWOW64\config\systemprofile\Desktop

Apparently excel needs these folders if it's not run interactively. Create both folders even if you are on a 64-bit OS.

显然excel需要这些文件夹,如果它不是以交互方式运行的。即使您使用的是64位操作系统,也可以创建这两个文件夹。

Let me know!

让我知道!

Rod Bowen

#3


1  

This has solved it for me:

这解决了我:

32Bit:

C:\Windows\System32\config\systemprofile\Desktop

64Bit:

C:\Windows\SysWOW64\config\systemprofile\Desktop

#1


4  

You need to specify the Full path to the Excel.exe application executable as well as the workbook to open.

您需要指定Excel.exe应用程序可执行文件的完整路径以及要打开的工作簿。

Location of Office Programs (64-bit Office on 64-bit Windows Server 2012)

Office程序的位置(64位Windows Server 2012上的64位Office)

  • Microsoft Office 2013
           "%PROGRAMFILES%\Microsoft Office\Office15\EXCEL.EXE"
  • Microsoft Office 2013“%PROGRAMFILES%\ Microsoft Office \ Office15 \ EXCEL.EXE”

  • Microsoft Office 2010
           "%PROGRAMFILES%\Microsoft Office\Office14\EXCEL.EXE"
  • Microsoft Office 2010“%PROGRAMFILES%\ Microsoft Office \ Office14 \ EXCEL.EXE”

  • Microsoft Office 2007
           "%PROGRAMFILES%\Microsoft Office\Office12\EXCEL.EXE"
  • Microsoft Office 2007“%PROGRAMFILES%\ Microsoft Office \ Office12 \ EXCEL.EXE”

  • Microsoft Office 2003
           "%PROGRAMFILES%\Microsoft Office\Office11\EXCEL.EXE"
  • Microsoft Office 2003“%PROGRAMFILES%\ Microsoft Office \ Office11 \ EXCEL.EXE”

  • Microsoft Word 2002
           "%PROGRAMFILES%\Microsoft Office\Office10\EXCEL.EXE"
  • Microsoft Word 2002“%PROGRAMFILES%\ Microsoft Office \ Office10 \ EXCEL.EXE”

  • Microsoft Word 2000
           "%PROGRAMFILES%\Microsoft Office\Office\EXCEL.EXE"
  • Microsoft Word 2000“%PROGRAMFILES%\ Microsoft Office \ Office \ EXCEL.EXE”

For a 32-bit Office version on a 64-bit operating system substitute %PROGRAMFILES(x86)% for %PROGRAMFILES%.

对于64位操作系统上的32位Office版本,将%PROGRAMFILES(x86)%替换为%PROGRAMFILES%。

Example of command line:

命令行示例:

"%PROGRAMFILES%\Microsoft Office\Office14\EXCEL.EXE" "C:\Users\user\Documents\MyWorkbook.xlsx"

Additional command lines options are available to open as read only, etc. See Command-line switches for Excel.

其他命令行选项可以打开为只读等。请参阅Excel的命令行开关。

#2


1  

Three important steps - How to Task Schedule an excel.xls(m) file

三个重要步骤 - 如何任务计划excel.xls(m)文件

simply:

  1. make sure the .vbs file is correct
  2. 确保.vbs文件正确无误

  3. set the Action tab correctly in Task Scheduler
  4. 在任务计划程序中正确设置“操作”选项卡

  5. don't turn on "Run whether user is logged on or not"
  6. 不要打开“运行用户是否登录”

IN MORE DETAIL...

更详细......

Here is an example .vbs file:

这是一个示例.vbs文件:

'
'   a .vbs file is just a text file containing visual basic code that has the extension renamed from .txt  to .vbs

 'Write Excel.xls  Sheet's full path here
 strPath = "C:\RodsData.xlsm" 

'Write the macro name - could try including module name
strMacro = "Update" '    "Sheet1.Macro2" 

'Create an Excel instance and set visibility of the instance
Set objApp = CreateObject("Excel.Application") 
objApp.Visible = True   '   or False 

'Open workbook; Run Macro; Save Workbook with changes; Close; Quit Excel
Set wbToRun = objApp.Workbooks.Open(strPath) 
objApp.Run strMacro     '   wbToRun.Name & "!" & strMacro 
wbToRun.Save 
wbToRun.Close 
objApp.Quit 

'Leaves an onscreen message!
MsgBox strPath & " " & strMacro & " macro and .vbs successfully completed!",         vbInformation 
'

In the Action tab (Task Scheduler):

在“操作”选项卡(任务计划程序)中:

set Program/script: = C:\Windows\System32\cscript.exe

set Program / script:= C:\ Windows \ System32 \ cscript.exe

set Add arguments (optional): = C:\MyVbsFile.vbs

set添加参数(可选):= C:\ MyVbsFile.vbs

Finally, don't turn on "Run whether user is logged on or not".

最后,不要打开“运行用户是否登录”。

That should work.

这应该工作。

Many people also need the following two folders created on their machine:

许多人还需要在他们的机器上创建以下两个文件夹:

32Bit:

C:\Windows\System32\config\systemprofile\Desktop

64Bit:

C:\Windows\SysWOW64\config\systemprofile\Desktop

Apparently excel needs these folders if it's not run interactively. Create both folders even if you are on a 64-bit OS.

显然excel需要这些文件夹,如果它不是以交互方式运行的。即使您使用的是64位操作系统,也可以创建这两个文件夹。

Let me know!

让我知道!

Rod Bowen

#3


1  

This has solved it for me:

这解决了我:

32Bit:

C:\Windows\System32\config\systemprofile\Desktop

64Bit:

C:\Windows\SysWOW64\config\systemprofile\Desktop