Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Printing a document using a batch file  (Read 4318 times)

0 Members and 1 Guest are viewing this topic.

ghaskins

  • Guest
Printing a document using a batch file
« on: April 26, 2007, 02:15:30 PM »
I need help!!! How can I create a batch file that opens up a document in excel and prints the document to specific printer?

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Printing a document using a batch file
« Reply #1 on: April 26, 2007, 06:11:37 PM »
Batch code does not generally do Windows. Using the print command on a  Excel workbook/worksheet will produce gruesome results.

A batch file could open an Excel workbook but printing it would only be possible with something like AutoIt, where you could design a macro to mimic your mouse as you go about printing the document.

Generally when dealing with Windows applications, you're better off utilizing a Windows script language.

 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

contrex

  • Guest
Re: Printing a document using a batch file
« Reply #2 on: April 28, 2007, 06:04:01 AM »

This type of Excel/batch interaction is often very useful. The
general technique for working with such MSOffice files is:

1) Create a dummy .XLS file that simply contains an
auto-open VBA macro that imports your actual Excel file,
prints it, and quits. Suppose the dummy .XLS file is:
C:\SOMEFOLDER\PrintMyFile.XLS

2) Use a batch file with the command:
start /w C:\SOMEFOLDER\PrintMyFile.XLS
which will start up the dummy file and the VBA macro
will do the work.

This process is preferable to simply putting the
auto-open macro in the main data file. If you did that
it would execute every time you opened the file. Since
you'll never open the dummy .XLS file directly yourself
you won't run into this problem by working in the way I
suggest.

This technique is easily adapted to far more complex
MSOffice/batch interaction.