PrintOut Method help

J

Jack Fredrick

How can the PrintOut Method be used to print the last page of the
first section in the document? The solution must work regardless of
the length and count of sections in the document.

Thank you
 
S

Stefan Blom

Try the following:

Sub PrintLastPageSectionOne()
Dim r As Range
Dim lastpage As Long
Set r = ActiveDocument.Sections(1).Range.Duplicate
r.Collapse wdCollapseEnd
lastpage = r.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.PrintOut Pages:="p1" & "s" & CStr(lastpage)
End Sub
 
J

Jack Fredrick

Try the following:

Sub PrintLastPageSectionOne()
Dim r As Range
Dim lastpage As Long
Set r = ActiveDocument.Sections(1).Range.Duplicate
r.Collapse wdCollapseEnd
lastpage = r.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.PrintOut Pages:="p1" & "s" & CStr(lastpage)
End Sub

I don't get it, the logic seems clear but it prints the entire
document, not only the last page of the first section.
 
S

Stefan Blom

Sorry, I noticed an error in the coding. This is the correct version:

Sub PrintLastPageSectionOne()
Dim r As Range
Dim lastpage As Long
Set r = ActiveDocument.Sections(1).Range.Duplicate
r.Collapse wdCollapseEnd
lastpage = r.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.PrintOut Pages:="p" & CStr(lastpage) & "s1"
End Sub
 
J

Jack Fredrick

Sorry, I noticed an error in the coding. This is the correct version:

Sub PrintLastPageSectionOne()
Dim r As Range
Dim lastpage As Long
Set r = ActiveDocument.Sections(1).Range.Duplicate
r.Collapse wdCollapseEnd
lastpage = r.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.PrintOut Pages:="p" & CStr(lastpage) & "s1"
End Sub

Wow, I missed the erroneous line. Anyway it still print the entire
document.
 
S

Stefan Blom

OK, I forgot the Range argument for the PrintOut method. I apologize. This
should do it (keeping fingers crossed):

Sub PrintLastPageSectionOne()
Dim r As Range
Dim lastpage As Long
Set r = ActiveDocument.Sections(1).Range.Duplicate
r.Collapse wdCollapseEnd
lastpage = r.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, _
Pages:="p" & CStr(lastpage) & "s1"
End Sub
 
J

Jack Fredrick

OK, I forgot the Range argument for the PrintOut method. I apologize. This
should do it (keeping fingers crossed):

Sub PrintLastPageSectionOne()
Dim r As Range
Dim lastpage As Long
Set r = ActiveDocument.Sections(1).Range.Duplicate
r.Collapse wdCollapseEnd
lastpage = r.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, _
Pages:="p" & CStr(lastpage) & "s1"
End Sub

Thanks works well.
 

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