locked
Printing Default set to Pages X--X RRS feed

  • Question

  • Jay Freedman in a similar post provided this macro to set the Default print value to "Current page"

    Sub FilePrint()
       With Dialogs(wdDialogFilePrint)
         .Range = wdPrintCurrentPage
         .Show
       End With
    End Sub

    Which works great, however, I have 2 problems:

    1) I'm trying to get the file to Default to Print Pages 1-2 (because it's a 10-page document which users normally only need to print the first two pages and people are killing trees by forgetting to change the values!) and

    2) I'm not sure where it should go in my macro. I've already got a Sub FilePrint()
    and Sub FilePrintDefault() macro listed in my code. Here's what I've got:

    Sub FilePrint()
       With ActiveDocument
            ' unprotect
            If .ProtectionType <> wdNoProtection Then
               .Unprotect Password:="snip"
            End If

           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
           Dialogs(wdDialogFilePrint).Show
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False

           ' reprotect
           .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
       End With
    End Sub

    Sub FilePrintDefault()
       With ActiveDocument
            ' unprotect
            If .ProtectionType <> wdNoProtection Then
               .Unprotect Password:="snip"
            End If

           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
           .PrintOut Background:=False
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False

           ' reprotect
           .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
       End With
    End Sub

    My other problem is I'm not a good enough VBA coder to know where to put it or how much of it to put, or for that matter, what to put.  I've tried .Range = wdPrintPage1-2 and .Range = wdPrintPages(1-2) but it's not working.  I'm obviously missing something!  So if someone could please indicate where to add the code and what code to add, I'd really appreciate it!!! 

    Thanks in advance! Please let me know if I can be clearer in my post. 



    Friday, April 15, 2011 7:15 PM

Answers

  • On Sat, 16 Apr 2011 03:37:20 +0000, Jay Freedman <jay.freedman@verizon.net>
    wrote:

    On Fri, 15 Apr 2011 23:13:52 +0000, Doug Robbins [MVP] wrote:

    Delete the line
          Dialogs(wdDialogFilePrint).Show

    Well, not quite -- that will eliminate the 10-page print but will leave the
    button printing on the 2-page print. You also need to move the .PrintOut
    command to the place previously occupied by the
    Dialogs(wdDialogFilePrint).Show command:

    On second thought, the previous macro might be too restrictive -- it wouldn't
    let you print anything more than the first two pages of any document. If you
    want to show the dialog and allow selection of any range, but just default to
    pages 1-2, then the macro should look like this:

    Sub FilePrint()
      With ActiveDocument
           ' unprotect
           If .ProtectionType <> wdNoProtection Then
              .Unprotect Password:="snip"
           End If
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
            With Dialogs(wdDialogFilePrint)
                .Range = wdPrintFromTo
                .From = 1
                .To = 2
                .Show
            End With
          .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False
           ' reprotect
          .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
      End With
    End Sub


    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org
    • Marked as answer by Dax ArrowayII Monday, April 18, 2011 3:26 PM
    Saturday, April 16, 2011 3:51 AM

All replies

  • Sub FilePrint()
      With ActiveDocument
           ' unprotect
           If .ProtectionType <> wdNoProtection Then
              .Unprotect Password:="snip"
           End If
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
          Dialogs(wdDialogFilePrint).Show
          .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False
           ' reprotect
          .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
          .PrintOut Range:=wdPrintFromTo, From:="1", To:="2"
      End With
    End Sub


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Dax ArrowayII" wrote in message news:2d14608f-58b3-49f1-937b-c54ec559af07@communitybridge.codeplex.com...

    Jay Freedman in a similar post provided this macro to set the Default print value to "Current page"

    Sub FilePrint()
       With Dialogs(wdDialogFilePrint)
         .Range = wdPrintCurrentPage
         .Show
       End With
    End Sub

    Which works great, however, I have 2 problems:

    1) I'm trying to get the file to Default to Print Pages 1-2 (because it's a 10-page document which users normally only need to print the first two pages and people are killing trees by forgetting to change the values!) and

    2) I'm not sure where it should go in my macro. I've already got a Sub FilePrint()
    and Sub FilePrintDefault() macro listed in my code. Here's what I've got:

    Sub FilePrint()
       With ActiveDocument
            ' unprotect
            If .ProtectionType <> wdNoProtection Then
               .Unprotect Password:="snip"
            End If

           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
           Dialogs(wdDialogFilePrint).Show
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False

           ' reprotect
           .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
       End With
    End Sub

    Sub FilePrintDefault()
       With ActiveDocument
            ' unprotect
            If .ProtectionType <> wdNoProtection Then
               .Unprotect Password:="snip"
            End If

           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
           .PrintOut Background:=False
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False

           ' reprotect
           .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
       End With
    End Sub

    My other problem is I'm not a good enough VBA coder to know where to put it or how much of it to put, or for that matter, what to put.  I've tried .Range = wdPrintPage1-2 and .Range = wdPrintPages(1-2) but it's not working.  I'm obviously missing something!  So if someone could please indicate where to add the code and what code to add, I'd really appreciate it!!!

    Thanks in advance! Please let me know if I can be clearer in my post.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Friday, April 15, 2011 8:46 PM
  • OH yes, yes, that's it but SO close but not just right.  So with that code it prints out the 2 pages but it also prints out the 10 pages.  So I go to File/Print and the dialog box presents with page range set to "All" selected.  If I hit OK, the 10 pages print, then the first 2 pages print.  Also, I'm thinking that the function of the FilePrint and FilePrintDefault macros are to print the doc without printing the macro button.  When I enter the code as indicated in the FilePrint section (nothing in the FilePrintDefault section, right?) the Macro button is hidden on the 10-page print but not on the 2-page print.  Should there be two different ones?  Or can they be combined? 

    Just a little more help please?



    Friday, April 15, 2011 9:47 PM
  • Delete the line
          Dialogs(wdDialogFilePrint).Show
     -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Dax ArrowayII" wrote in message news:7aa90299-63f5-49aa-a8c0-221fc9a3eade@communitybridge.codeplex.com...

    OH yes, yes, that's it but SO close but not just right.  So with that code it prints out the 2 pages but it also prints out the 10 pages.  So I go to File/Print and the dialog box presents with page range set to "All" selected.  If I hit OK, the 10 pages print, then the first 2 pages print. Also, I'm thinking that the function of the FilePrint and FilePrintDefault macros are to print the doc without printing the macro button.  When I enter the code as indicated in the FilePrint section (nothing in the FilePrintDefault section, right?) the Macro button is hidden on the 10-page print but not on the 2-page print.  Should there be two different ones?  Or can they be combined?

    Just a little more help please?


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Friday, April 15, 2011 11:13 PM
  • On Fri, 15 Apr 2011 23:13:52 +0000, Doug Robbins [MVP] wrote:

    Delete the line
          Dialogs(wdDialogFilePrint).Show

    Well, not quite -- that will eliminate the 10-page print but will leave the
    button printing on the 2-page print. You also need to move the .PrintOut
    command to the place previously occupied by the
    Dialogs(wdDialogFilePrint).Show command:

    Sub FilePrint()
      With ActiveDocument
           ' unprotect
           If .ProtectionType <> wdNoProtection Then
              .Unprotect Password:="snip"
           End If
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
          .PrintOut Range:=wdPrintFromTo, From:="1", To:="2"
          .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False
           ' reprotect
          .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
      End With
    End Sub


    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org
    Saturday, April 16, 2011 3:37 AM
  • On Sat, 16 Apr 2011 03:37:20 +0000, Jay Freedman <jay.freedman@verizon.net>
    wrote:

    On Fri, 15 Apr 2011 23:13:52 +0000, Doug Robbins [MVP] wrote:

    Delete the line
          Dialogs(wdDialogFilePrint).Show

    Well, not quite -- that will eliminate the 10-page print but will leave the
    button printing on the 2-page print. You also need to move the .PrintOut
    command to the place previously occupied by the
    Dialogs(wdDialogFilePrint).Show command:

    On second thought, the previous macro might be too restrictive -- it wouldn't
    let you print anything more than the first two pages of any document. If you
    want to show the dialog and allow selection of any range, but just default to
    pages 1-2, then the macro should look like this:

    Sub FilePrint()
      With ActiveDocument
           ' unprotect
           If .ProtectionType <> wdNoProtection Then
              .Unprotect Password:="snip"
           End If
           .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = True
            With Dialogs(wdDialogFilePrint)
                .Range = wdPrintFromTo
                .From = 1
                .To = 2
                .Show
            End With
          .Bookmarks("RunSpellCheckButton").Range.Font.Hidden = False
           ' reprotect
          .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="snip"
      End With
    End Sub


    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org
    • Marked as answer by Dax ArrowayII Monday, April 18, 2011 3:26 PM
    Saturday, April 16, 2011 3:51 AM
  • I bow to thee, oh Word Gurus!!!  Thank you SO much.  Works perfect.  I could not have done it without you!  --Dax
    Monday, April 18, 2011 3:26 PM