Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Command line batch print - HOWTO

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barry - 22 Aug 2006 11:33 GMT
No help needed, just uploading info after my longish search so other
can make use of this :D

I needed a way to batch print a load of word docs in a folder, using a
batch file.

Just create a batch file and load the code into it.
Dobule click or run the file and all docs will be sent to printer and
closed in sequence.
(You do of course need word installed to do this)

Here's the code:

==========================

cls

rem create batch file that runs word
echo "c:\Program Files\Microsoft Office\Office10\winword.exe" %%1 /a
/mfileprintdefault /mFileExit > wordprint.bat
echo move %%1 printed\%%1 >> wordprint.bat

rem create a directory listing of word docs
dir /b *.doc > dirlist.txt

rem print and move the docs using created batch file
for /F %%a in (dirlist.txt) do wordprint.bat %%a

rem cleanup
del dirlist.txt
del wordprint.bat

echo
echo finished !!

==========================
Barry - 30 Aug 2006 10:43 GMT
slightly improved, with error handling

===========================

echo off
cls

rem create printed subfolder
md printed

rem create a directory listing of word docs
dir /b *.doc > dirlist.txt

rem print and move the docs using created batch file
for /F "delims=," %%a in (dirlist.txt) do (
    "c:\Program Files\Microsoft Office\Office10\winword.exe" "%%a" /a
/mfileprintdefault /mFileExit
    move "%%a" "printed\%%a"
    )

rem inform user of printing ok or not, and pause to allow for cleanup
cls
echo ===================
if not errorlevel 1 goto else
    echo An error occurred, please check your documents (filelist opening
now).
    start dirlist.txt
    goto end
:else
    echo All doc files sent to printer and moved to Printed folder.
:end
pause

rem cleanup
del dirlist.txt
del wordprint.bat
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.