Have a word doc print one copy on open, then close

E

eggman

I have the following vba code:

Sub Macro1()
' print 1 copy
Application.PrintOut Copies:=1
' close word
Application.Quit
End Sub

Where would I place the above code so that it:

1: Runs upon opening the document it is placed in
2: Does not ask to enable macros
3: Does not ask to save upon closing after it prints

TIA!!!
 
C

Chad DeMeyer

eggman,

1: To run upon opening the document it is placed in, it needs to either be
named AutoOpen, or be named "Document_Open" and reside in the ThisDocument
module.
2: There is no way to prevent the enable macros prompt. If the user has
their macro security set to Medium, they will get the prompt. If they have
security set to High, they won't see the prompt but the macro will be
automatically disabled. The only exceptions are if you digitally sign the
macro project and the user adds you to their list of trusted sources; or if
the user has their macro security configured to automatically trust
installed templates and add-ins and you make the document a template in
their User or Workgroup Templates folder or an Add-In in their Word or
Office Startup folder.
3: Application.Quit SaveChanges:=wdDoNotSaveChanges

Regards,
Chad
 
E

eggman

Chad (or anyone else willing to help),

Thanks for your help... it now closes itself, and runs on opening. But for
whatever reason, it will not print. It gets sent to my printer (the little
printer in the system tray pops up), but there is no out put. Do I have
something wrong in the print command:

Sub AutoOpen()
' print 1 copy
Application.PrintOut Copies:=1
' close word
Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub

Do I have to select or define a range or print settings? I used the macro
recorder to get that command and then trimmed what I deemed to be "fat". Do
I really need all of those commands, or am I simply missing one or two
important ones.

Thanks again,
 
J

Jezebel

Chad DeMeyer said:
eggman,

1: To run upon opening the document it is placed in, it needs to either be
named AutoOpen, or be named "Document_Open" and reside in the ThisDocument
module.


Or in the template on which the document is based.
 
S

Steve Lang

Yo "eggman,"

Try setting the background to false, so the print will complete before your
macro continues. It may be that the application.quit event is firing before
the document completes its print spool, so no document is available to
print.

Activedocument.Printout Background:= False

HTH and have a great day!

Steve
 
E

eggman

That was it!! Thanks again to Chad and Steve for your help... here is the
final version of the macro in case anyone is interested:

Sub AutoOpen()
' print 1 copy
Application.PrintOut Range:=wdPrintAllDocument, Copies:=1,
Background:=False
' close word
Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub
 

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