Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jan 2003
    Location
    Den Haag, Netherlands
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro print and shut down (Word XP)

    Good afternoon,

    I want to design a macro which - when I open the document - prints this document and shuts down Word. Can anyone tell me how to do this?

    Thanks,
    Daphne <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> (I'm sick of eating little bananasweets)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro print and shut down (Word XP)

    Hi Daphne,

    Isn't it easier to print the document directly from Windows Explorer? Either select the document in the Explorer, then select File | Print, or right click the document in the Explorer and select Print. That way, you don't need a macro.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro print and shut down (Word XP)

    Daphne
    Or you can put a shortcut to your printer in the Sendto Folder and right click the file then click Send to printer.
    Peter

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro print and shut down (Word XP)

    That's possible, but if there are other documents open with unsaved changes, the user will get prompts (or the changes will be committed wanted or not, or they will be lost, depending on your design). Not sure the effort to create a bulletproof solution is worthwhile here if you can use the other methods suggested.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2003
    Location
    Den Haag, Netherlands
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro print and shut down (Word XP)

    I shoud have been more precise...
    It's about a document which is generated by another program. This program opens Word with the labels or envelops that have to be printed. So I want to add a macro to my maindocument that Word prints the labels or envelops and than closes Word. There is no other use of Word so it doesn't matter where I save that macro....

    Is this more specified?

    Many thanks in advance,
    Daphne

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro print and shut down (Word XP)

    OK, here you go.
    <UL><LI>Activate the Visual Basic Editor (Alt+F11)
    <LI>Activate the Project Explorer (Ctrl+R)
    <LI>Click on Normal
    <LI>Select Insert | Module (Invoegen | Module in Dutch)
    <LI>Type or paste the following macro into the module window that appears:

    Sub PrintAndQuit()
    ActiveDocument.PrintOut Background:=False
    Application.Quit SaveChanges:=wdDoNotSaveChanges
    End Sub

    <LI>Select File | Save Normal
    <LI>Switch back to Word
    <LI>Please be aware that the macro will print the active document and then quit Word without saving any open document, so be careful while testing.
    <LI>You can execute the macro by selecting Tools | Macro | Macros... (Extra | Macro | Macros... in Dutch, or press Alt+F8), then selecting PrintAndQuit and clicking Run (Uitvoeren).
    <LI>For ease of use, you can assign the macro to a toolbar button and/or keyboard shortcut. Select Tools | Customize... (Extra | Aanpassen..) to do so.[/list]Hope this helps.

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Macro print and shut down (Word XP)

    If you want a macro to run automatically then you could call it from AutoOpen .
    If you know the filename of the document that you expect to print then you could have some code that looks a bit like (Untested, just typed in here)

    Sub AutoOpen
    if Application.Documents(1).Name = "The name I expect here" Then
    ActiveDocument.PrintOut Background:=False
    If Application.Documents.Count > 1 Then
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    Else
    Application.Quit SaveChanges:=wdDoNotSaveChanges
    End If
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •