Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Automatic Print on Open (Word VBA 2003)

    Hi,

    Im trying to write a macro that disables the user's print options and automatically prints the document and then closes automatically, as detailed below, albeit I havent got to the auto close bit yet;

    Sub AutoExec()
    ActiveDocument.PrintOut
    Call DisablePrint
    'Call EnablePrint
    End Sub


    Sub DisablePrint()
    ToggleItems False
    End Sub

    Sub EnablePrint()
    ToggleItems True
    End Sub

    Sub ToggleItems(f As Boolean)
    On Error Resume Next
    ' File menu items
    CommandBars("File").Controls("Print...").Enabled = f
    CommandBars("File").Controls("Print").Enabled = f
    ' Toolbar items
    CommandBars.FindControl(ID:=4).Enabled = f
    CommandBars.FindControl(ID:=2521).Enabled = f
    End Sub

    When I open Word I get the attached error messages. Ive tried to move the 'ActiveDocument.PrintOut' to various different points of the macro, but no luck!

    Any suggestions or tips will be grately appreciated.

    Many thanks.
    Lee
    Attached Files Attached Files

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

    Re: Automatic Print on Open (Word VBA 2003)

    You shouldn't put ActiveDocument.PrintOut in a macro named AutoExec. AutoExec is executed only once, when Word is started. Try putting it in AutoOpen; this is executed when a document is opened.

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

    Re: Automatic Print on Open (Word VBA 2003)

    On second thought, AutoOpen might not be a good idea either. If you want the code to apply to a specific document, put the code in the Document_Open event procedure in the ThisWorkbook module of that document.

  4. #4
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Automatic Print on Open (Word VBA 2003)

    Hi Hans,

    Many thanks for your responses.

    Unfortunately, Im not sure where I need to go with regard to Document_Open event procedure in the ThisWorkbook module, as Im quite inexperienced Im afraid.

    If possible would you mind telling me how I get to the Document_Open event please? Also I cant seem to find ThisWorkbook, all I can see is ThisDocument.

    Many thanks for your help and patience on this.

    Cheers.
    Lee

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

    Re: Automatic Print on Open (Word VBA 2003)

    Oops, I wasn't paying attention. I should have mentioned ThisDocument instead of ThisWorkbook (ThisWorkbook is for Excel).

    Sorry for the confusion! <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

  6. #6
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Automatic Print on Open (Word VBA 2003)

    No problem, I'll have another look, when I work on it again tomorrow.

    Many thanks for your help Hans.

    Cheers.
    Lee

Posting Permissions

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