+ Reply to Thread
Results 1 to 4 of 4

Printing selected pages in a Word document

  1. #1
    Registered User
    Join Date
    05-02-2006
    Posts
    80

    Printing selected pages in a Word document

    Evening all,

    Here's my problem
    I'm trying to get a macro going that will only print certain pages of a document, in this case I want all the pages from 1 to the current page selected.
    I've dimmed "p" as a variant and it has the value of the current page (say 3 for example).
    Then the code goes like this:

    With Word <---previously dimmed as word.application

    .PrintOut Range:=wdPrintFromTo, From:="1", To:="p"

    I've also tried p without the quotes, omitting the range variant, p dimmed as an integer, using Pages:="1-" & p instead of the From, To thing and other stuff but it ain't working!>!>! Sure if I make p a number than that works okay but I need it to be a variable because it's gonig to be different each time.

    Any suggestions, because I'm sure the rainforests aren't going to appreciate me carrying on with this.

    Thanks, Tris

  2. #2
    Dave Peterson
    Guest

    Re: Printing selected pages in a Word document

    I recorded a macro in MSWord and got this line:

    Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
    wdPrintDocumentContent, Copies:=1, Pages:="1-3", PageType:= _
    wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
    False, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
    PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

    So maybe your code should look more like:

    With Word
    .PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
    wdPrintDocumentContent, Copies:=1, Pages:="1-" & p
    end with

    I used MSWord 2003.

    If this doesn't work, I'd record a macro in Word that does what you want and
    compare that with your code.

    Tristan wrote:
    >
    > Evening all,
    >
    > Here's my problem
    > I'm trying to get a macro going that will only print certain pages of a
    > document, in this case I want all the pages from 1 to the current page
    > selected.
    > I've dimmed "p" as a variant and it has the value of the current page
    > (say 3 for example).
    > Then the code goes like this:
    >
    > With Word <---previously dimmed as word.application
    >
    > PrintOut Range:=wdPrintFromTo, From:="1", To:="p"
    >
    > I've also tried p without the quotes, omitting the range variant, p
    > dimmed as an integer, using Pages:="1-" & p instead of the From, To
    > thing and other stuff but it ain't working!>!>! Sure if I make p a
    > number than that works okay but I need it to be a variable because it's
    > gonig to be different each time.
    >
    > Any suggestions, because I'm sure the rainforests aren't going to
    > appreciate me carrying on with this.
    >
    > Thanks, Tris
    >
    > --
    > Tristan
    > ------------------------------------------------------------------------
    > Tristan's Profile: http://www.excelforum.com/member.php...o&userid=34061
    > View this thread: http://www.excelforum.com/showthread...hreadid=557029


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    05-02-2006
    Posts
    80
    Thanks for your reply Dave,

    That's pretty much the same avenue I went down and I tried the code with the Pages:="1-" & p bit in it.

    I couldn't get it to do what I wanted it to. On most of the occassions (i tried a few variations on a theme) the document printed out but it printed all the pages instead of the few I wanted, i.e. it wasn't registering the p as a number.

  4. #4
    Dave Peterson
    Guest

    Re: Printing selected pages in a Word document

    There was a difference in what to print, too.

    wdPrintRangeOfPages = 4
    wdPrintFromTo = 3

    But if you're using wdPrintFromTo, I would think I'd try:

    word.PrintOut Range:=wdPrintFromTo, From:=1, To:=p

    Notice that the quotes are gone.







    Tristan wrote:
    >
    > Thanks for your reply Dave,
    >
    > That's pretty much the same avenue I went down and I tried the code
    > with the Pages:="1-" & p bit in it.
    >
    > I couldn't get it to do what I wanted it to. On most of the occassions
    > (i tried a few variations on a theme) the document printed out but it
    > printed all the pages instead of the few I wanted, i.e. it wasn't
    > registering the p as a number.
    >
    > --
    > Tristan
    > ------------------------------------------------------------------------
    > Tristan's Profile: http://www.excelforum.com/member.php...o&userid=34061
    > View this thread: http://www.excelforum.com/showthread...hreadid=557029


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1