can macro open file, print and close Word



kbgrunt
07-09-2005, 11:03 PM
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.

Shauna Kelly
07-09-2005, 11:03 PM
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


"kbgrunt" <kbgrunt@discussions.microsoft.com> wrote in message
news:8A890314-2F7C-41CE-8BAF-CB97E2110810@microsoft.com...
> 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.

kbgrunt
07-09-2005, 11:03 PM
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

"Shauna Kelly" wrote:

> 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
>
>
> "kbgrunt" <kbgrunt@discussions.microsoft.com> wrote in message
> news:8A890314-2F7C-41CE-8BAF-CB97E2110810@microsoft.com...
> > 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.
>
>
>

Doug Robbins
07-09-2005, 11:03 PM
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
"kbgrunt" <kbgrunt@discussions.microsoft.com> wrote in message
news:1C5003DA-9172-4D8F-8B61-C3CF9B146915@microsoft.com...
> 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
>
> "Shauna Kelly" wrote:
>
>> 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
>>
>>
>> "kbgrunt" <kbgrunt@discussions.microsoft.com> wrote in message
>> news:8A890314-2F7C-41CE-8BAF-CB97E2110810@microsoft.com...
>> > 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.
>>
>>
>>


can macro open file, print and close Word