can macro open file, print and close Word

K

kbgrunt

With help from Jay Freedman I now have a macro that I am using inside a batch
file
to open an ASCII text file from a unix system, and compress the print.

Is it possible to take it a step further and actually print the file then
close Word?

This is the basic macro so far, I have added some margin settings...

Public Sub SetupReport()
Documents.Open "C:\docs\wide.txt"
ActiveDocument.PageSetup.Orientation = wdOrientLandscape
With ActiveDocument.Range
.Font.Name = "Courier New"
.Font.Size = 7
End With
End Sub

Thanks.
 
S

Shauna Kelly

Hi kbgrunt

Assuming that you don't need to save the changes you've made, the following
should work:

Public Sub SetupReport()
Documents.Open "d:\d\test\test1.doc"
With ActiveDocument
.PageSetup.Orientation = wdOrientLandscape
With .Range
.Font.Name = "Courier New"
.Font.Size = 7
End With
.PrintOut
End With
Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
K

kbgrunt

Shauna, thanks for the help. If I add just the .PrintOut the document
prints. If I add both the PrintOut and Application.Quit - Word opens, see
the document, the document closes then Word hangs with a blank grey window
and the report never prints. My guess is that Word is attempting to quit
while report is still printing.

Is there a way to pause/wait/sleep to allow report time to spool/print,
before Word attempts to quit?
Windows XP Pro, Word 2000. Will use this with Word 2000-2003.

Thanks
 
D

Doug Robbins

Use

..PrintOut Background:=False

That will prevent the next command in the macro from being executed until
the document has finished printing.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top