Printing an excel document via the command queue


Posted by Christofer Lindqvist on May 22, 2001 6:11 AM

Hi
is it possible to print an excel document by making a batch file or in dos (command) ????

for ex.
to make a batch file of some sort that when i click it, it opens up the excel file that i specified, print it, and closes excel !?

you might think its useless since theres other ways of doing it in windows, but i really need this to work !!!

Thanks !

Chris

Posted by Kevin James on May 22, 2001 4:40 PM

Hi Chris:

I dug out my DOS books to see if this was possible.

This command will work with dos files:
copy [filename] prn

But try that with a windows-based file and you will get page after page of one-liner gobbledigook. I was able to stop my printer after 8 pages.

Kevin

Posted by Tuc on May 22, 2001 6:34 PM

Have you tried VBScript (Windows Scripting Host)?

Hi Chris,


I wrote a little VBScript (.VBS) file below that you can look at. The Windows Scripting Host is built into Windows 98, ME, and 2000. It is a simple add on in Windows 95 and NT. Documentation is available at www.microsoft.com/vbscript and there are several web sites devoted to VBS.

This declares three variables, launches Excel (in background), opens a workbook, points to the first sheet, prints that sheet, closes the workbook, and then quits the Excel application.

dim xlapp, xlwb, xlws
set xlapp = CreateObject("Excel.Application")
set xlwb = xlapp.Workbooks.Open("C:\WINDOWS\Desktop\Report.xls")
set xlws = xlwb.worksheets(1)
xlws.PrintOut
xlwb.Close
xlapp.quit

I hope this helps you out or gives you another Idea. I believe that VBS file can be called from a batch file.

Tuc



Posted by Ivan Moala on May 23, 2001 6:22 AM

Re: Have you tried VBScript (Windows Scripting Host)?

Tuc
Is right in that it can be called via a batch file
in Dos mode. Will run in NT enviromnent
Suggest you have a look @ Tucs suggested sites for info

Ivan