close

Opening Excel 2003 from the command-line as follows works:
quot;C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXEquot; /e C:\excelFile.xls

But how do I print from the command-line?

Thanks.

The only command line switches that I know of are /r for read-onoyo, /e to
prevent the display of the startup screen and a blank workbook, and /p to
specify the working folder path.

I don't believe you initiate and Excel print job from the command line.
--
Kevin Backmannquot;eeidfnquot; wrote:

gt; Opening Excel 2003 from the command-line as follows works:
gt; quot;C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXEquot; /e C:\excelFile.xls
gt;
gt; But how do I print from the command-line?
gt;
gt; Thanks.

I don't think you can do it directly from a command line. You could use a
somewhat indirect approach with a vbScript. If you save what I've got
between the lines below as a text file with a VBS extension (for example,
C:\Test\PrintWkbk.vbs) then you can either drag xls files into the vbs or a
shortcut to it or you can use a command line like:
C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;
to print the Workbook. Note that if you have disabled file associations for
scripts, you may have to use the command line
WScript.exe C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;

__________________________________________________ ___________

Const xlDoNotSaveChanges = 2

Dim fso, oXL, oWkbk

Set fso = CreateObject(quot;Scripting.FileSystemObjectquot;)
Set oXL = CreateObject(quot;Excel.Applicationquot;)

oXL.Visible = False

If WScript.Arguments.Count = 0 Then
WScript.Quit
Else
For A = 0 To (WScript.Arguments.Count - 1)
If (Right(WScript.Arguments.Item(A), 3) = quot;xlsquot;) _
AND fso.FileExists(WScript.Arguments.Item(A)) Then
Set oWkbk = oXL.Workbooks.Open(WScript.Arguments.Item(A))
oWkbk.PrintOut
oWkbk.Close xlDoNotSaveChanges
End If
Next
End If

oXL.Quit
Set fso = Nothing
Set oXL = Nothing
__________________________________________________ ___________

Steve Yandl

quot;eeidfnquot; gt; wrote in message
...
gt; Opening Excel 2003 from the command-line as follows works:
gt; quot;C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXEquot; /e C:\excelFile.xls
gt;
gt; But how do I print from the command-line?
gt;
gt; Thanks.
Steve,
That worked great. It also works if the file happens to be open already.

The only drawback is that VBS support is required in addition to Excel being
installed. Is WScript and Visual Basic Script standard on Windows 2000 and
XP?

Thanks.

quot;Steve Yandlquot; wrote:

gt; I don't think you can do it directly from a command line. You could use a
gt; somewhat indirect approach with a vbScript. If you save what I've got
gt; between the lines below as a text file with a VBS extension (for example,
gt; C:\Test\PrintWkbk.vbs) then you can either drag xls files into the vbs or a
gt; shortcut to it or you can use a command line like:
gt; C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;
gt; to print the Workbook. Note that if you have disabled file associations for
gt; scripts, you may have to use the command line
gt; WScript.exe C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;
gt;
gt; __________________________________________________ ___________
gt;
gt; Const xlDoNotSaveChanges = 2
gt;
gt; Dim fso, oXL, oWkbk
gt;
gt; Set fso = CreateObject(quot;Scripting.FileSystemObjectquot;)
gt; Set oXL = CreateObject(quot;Excel.Applicationquot;)
gt;
gt; oXL.Visible = False
gt;
gt; If WScript.Arguments.Count = 0 Then
gt; WScript.Quit
gt; Else
gt; For A = 0 To (WScript.Arguments.Count - 1)
gt; If (Right(WScript.Arguments.Item(A), 3) = quot;xlsquot;) _
gt; AND fso.FileExists(WScript.Arguments.Item(A)) Then
gt; Set oWkbk = oXL.Workbooks.Open(WScript.Arguments.Item(A))
gt; oWkbk.PrintOut
gt; oWkbk.Close xlDoNotSaveChanges
gt; End If
gt; Next
gt; End If
gt;
gt; oXL.Quit
gt; Set fso = Nothing
gt; Set oXL = Nothing
gt; __________________________________________________ ___________
gt;
gt; Steve Yandl
gt;
gt;
gt;
gt;
gt; quot;eeidfnquot; gt; wrote in message
gt; ...
gt; gt; Opening Excel 2003 from the command-line as follows works:
gt; gt; quot;C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXEquot; /e C:\excelFile.xls
gt; gt;
gt; gt; But how do I print from the command-line?
gt; gt;
gt; gt; Thanks.
gt;
gt;
gt;

Yes, vbs support and the Script Host are included. It can be downloaded for
free from Microsoft if you have any Win98 systems but it's standard on WinXP
and Win2k.

I like to place shortcuts to this sort of script in my SendTo folder rather
than type out command lines with arguments but do what suits your needs
best.

Stevequot;eeidfnquot; gt; wrote in message
...
gt; Steve,
gt; That worked great. It also works if the file happens to be open already.
gt;
gt; The only drawback is that VBS support is required in addition to Excel
gt; being
gt; installed. Is WScript and Visual Basic Script standard on Windows 2000
gt; and
gt; XP?
gt;
gt; Thanks.
gt;
gt; quot;Steve Yandlquot; wrote:
gt;
gt;gt; I don't think you can do it directly from a command line. You could use
gt;gt; a
gt;gt; somewhat indirect approach with a vbScript. If you save what I've got
gt;gt; between the lines below as a text file with a VBS extension (for example,
gt;gt; C:\Test\PrintWkbk.vbs) then you can either drag xls files into the vbs or
gt;gt; a
gt;gt; shortcut to it or you can use a command line like:
gt;gt; C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;
gt;gt; to print the Workbook. Note that if you have disabled file associations
gt;gt; for
gt;gt; scripts, you may have to use the command line
gt;gt; WScript.exe C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;
gt;gt;
gt;gt; __________________________________________________ ___________
gt;gt;
gt;gt; Const xlDoNotSaveChanges = 2
gt;gt;
gt;gt; Dim fso, oXL, oWkbk
gt;gt;
gt;gt; Set fso = CreateObject(quot;Scripting.FileSystemObjectquot;)
gt;gt; Set oXL = CreateObject(quot;Excel.Applicationquot;)
gt;gt;
gt;gt; oXL.Visible = False
gt;gt;
gt;gt; If WScript.Arguments.Count = 0 Then
gt;gt; WScript.Quit
gt;gt; Else
gt;gt; For A = 0 To (WScript.Arguments.Count - 1)
gt;gt; If (Right(WScript.Arguments.Item(A), 3) = quot;xlsquot;) _
gt;gt; AND fso.FileExists(WScript.Arguments.Item(A)) Then
gt;gt; Set oWkbk = oXL.Workbooks.Open(WScript.Arguments.Item(A))
gt;gt; oWkbk.PrintOut
gt;gt; oWkbk.Close xlDoNotSaveChanges
gt;gt; End If
gt;gt; Next
gt;gt; End If
gt;gt;
gt;gt; oXL.Quit
gt;gt; Set fso = Nothing
gt;gt; Set oXL = Nothing
gt;gt; __________________________________________________ ___________
gt;gt;
gt;gt; Steve Yandl
gt;gt;
gt;gt;
gt;gt;
gt;gt;
gt;gt; quot;eeidfnquot; gt; wrote in message
gt;gt; ...
gt;gt; gt; Opening Excel 2003 from the command-line as follows works:
gt;gt; gt; quot;C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXEquot; /e
gt;gt; gt; C:\excelFile.xls
gt;gt; gt;
gt;gt; gt; But how do I print from the command-line?
gt;gt; gt;
gt;gt; gt; Thanks.
gt;gt;
gt;gt;
gt;gt;
Actually, even if you have Win98 systems, the scripting runtimes are
standard. Some great new tools that involve WMI (which were not used for
the above script) require more than is found in Win98 but that isn't an
issue here. Your only concern will be systems where script support has been
turned off for security.

Stevequot;Steve Yandlquot; gt; wrote in message
. ..
gt; Yes, vbs support and the Script Host are included. It can be downloaded
gt; for free from Microsoft if you have any Win98 systems but it's standard on
gt; WinXP and Win2k.
gt;
gt; I like to place shortcuts to this sort of script in my SendTo folder
gt; rather than type out command lines with arguments but do what suits your
gt; needs best.
gt;
gt; Steve
gt;
gt;
gt; quot;eeidfnquot; gt; wrote in message
gt; ...
gt;gt; Steve,
gt;gt; That worked great. It also works if the file happens to be open already.
gt;gt;
gt;gt; The only drawback is that VBS support is required in addition to Excel
gt;gt; being
gt;gt; installed. Is WScript and Visual Basic Script standard on Windows 2000
gt;gt; and
gt;gt; XP?
gt;gt;
gt;gt; Thanks.
gt;gt;
gt;gt; quot;Steve Yandlquot; wrote:
gt;gt;
gt;gt;gt; I don't think you can do it directly from a command line. You could use
gt;gt;gt; a
gt;gt;gt; somewhat indirect approach with a vbScript. If you save what I've got
gt;gt;gt; between the lines below as a text file with a VBS extension (for
gt;gt;gt; example,
gt;gt;gt; C:\Test\PrintWkbk.vbs) then you can either drag xls files into the vbs
gt;gt;gt; or a
gt;gt;gt; shortcut to it or you can use a command line like:
gt;gt;gt; C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;
gt;gt;gt; to print the Workbook. Note that if you have disabled file associations
gt;gt;gt; for
gt;gt;gt; scripts, you may have to use the command line
gt;gt;gt; WScript.exe C:\Test\PrintWkbk.vbs quot;C:\xlFiles\Text.xlsquot;
gt;gt;gt;
gt;gt;gt; __________________________________________________ ___________
gt;gt;gt;
gt;gt;gt; Const xlDoNotSaveChanges = 2
gt;gt;gt;
gt;gt;gt; Dim fso, oXL, oWkbk
gt;gt;gt;
gt;gt;gt; Set fso = CreateObject(quot;Scripting.FileSystemObjectquot;)
gt;gt;gt; Set oXL = CreateObject(quot;Excel.Applicationquot;)
gt;gt;gt;
gt;gt;gt; oXL.Visible = False
gt;gt;gt;
gt;gt;gt; If WScript.Arguments.Count = 0 Then
gt;gt;gt; WScript.Quit
gt;gt;gt; Else
gt;gt;gt; For A = 0 To (WScript.Arguments.Count - 1)
gt;gt;gt; If (Right(WScript.Arguments.Item(A), 3) = quot;xlsquot;) _
gt;gt;gt; AND fso.FileExists(WScript.Arguments.Item(A)) Then
gt;gt;gt; Set oWkbk = oXL.Workbooks.Open(WScript.Arguments.Item(A))
gt;gt;gt; oWkbk.PrintOut
gt;gt;gt; oWkbk.Close xlDoNotSaveChanges
gt;gt;gt; End If
gt;gt;gt; Next
gt;gt;gt; End If
gt;gt;gt;
gt;gt;gt; oXL.Quit
gt;gt;gt; Set fso = Nothing
gt;gt;gt; Set oXL = Nothing
gt;gt;gt; __________________________________________________ ___________
gt;gt;gt;
gt;gt;gt; Steve Yandl
gt;gt;gt;
gt;gt;gt;
gt;gt;gt;
gt;gt;gt;
gt;gt;gt; quot;eeidfnquot; gt; wrote in message
gt;gt;gt; ...
gt;gt;gt; gt; Opening Excel 2003 from the command-line as follows works:
gt;gt;gt; gt; quot;C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXEquot; /e
gt;gt;gt; gt; C:\excelFile.xls
gt;gt;gt; gt;
gt;gt;gt; gt; But how do I print from the command-line?
gt;gt;gt; gt;
gt;gt;gt; gt; Thanks.
gt;gt;gt;
gt;gt;gt;
gt;gt;gt;
gt;
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()