Count pages in Section and print just those pages

J

Jeanette

Credit to Dave Lett for the code shown below, but I'd like someone to
take it further for me (code please - don't have a clue!). My
documents comprise the following:

Section 1 - text with endnote references, followed by odd page section
break
Section 2 - Cover page, followed by odd page section break
Section 3 - Introductory text, as well as the endnote text

Document gets printed double-sided, with each section starting on a
facing (odd) page. There is nothing wrong with the document, works
perfectly all the time. HOWEVER, what I need is to print a final
version without the endnotes. I have code already that makes the
endnote references into hidden text in the body of the document
(Section 1) - that's great. I can can also manually print p1s1-p5s1,
s2 (p1s1-p5s1 being the current number of pages in the document and s2
being the Cover page).

What I don't know and need desparately, is how to count the number of
pages in Section 1 (because this changes all the time) and then print
just those particular pages with s2.

I saw this code and grabbed it (thank you so much Dave!) and I'm
halfway there - this tells me the number of pages in section 1 - but p
l e a s e can someone help in supplying the code to send the result to
print instead of a message???

I've been at this all day, so all help gratefully received!!!!
Jeanette

Public Sub CountPagesInCurrentSection()
Dim oRng As Range
Dim s As String
' use the current section
Set oRng = Selection.Sections(1).Range
With oRng
.Collapse wdCollapseStart
.Fields.Add _
Range:=oRng, _
Type:=wdFieldSectionPages
.MoveEnd unit:=wdCharacter, Count:=1
End With
s = oRng.Fields(1).Result & " pages in the current section."
oRng.Fields(1).Delete
MsgBox s
 
A

Art H

Review PrintOut and its options in help. See if this works for you.
Application.PrintOut Pages:="s1,s2"
 
J

Jeanette

Review PrintOut and its options in help. See if this works for you.
  Application.PrintOut Pages:="s1,s2"

Thanks so much for replying Art, but your solution sadly won't work :-
( The problem I am having is with the endnotes. Whilst they exist at
the end of the document (which is in section 3), being linked to the
endnote reference marks in section 1 means you cannot just printout
"s1", because the endnotes get printed out too! If I manually print
pages p1s1 - p5s1 (for example), I only get what I need and this is
what I am trying to achieve. When I run the pasted code above in my
document, I get a message that gives me the correct result - so to go
further, I need that result set in a "range" and then send the "range"
to print. Hope I've clarified things a bit better. I'd be extremely
grateful for any code that will do the trick!!!
 
A

Art H

Sorry that I got confused.

I have Word 2007 and 2010. When I print S1 and my endnotes are at the
end of the document instead of end of the section, all I get are the
pages of section 1 without any endnotes, as the endnotes exist on a
page I am not printing.

Anyway, I modified (see comments that start with Added) your code to
achieve what I believe you are after. See if this works for you.

Public Sub CountPagesInCurrentSection()
Dim oRng As Range
Dim s As String
Dim px As String 'Added, save the number of pages in the
section

' use the current section
Set oRng = Selection.Sections(1).Range
With oRng
.Collapse wdCollapseStart
.Fields.Add _
Range:=oRng, _
Type:=wdFieldSectionPages
.MoveEnd unit:=wdCharacter, Count:=1
End With
px = oRng.Fields(1).Result 'Added, the number of pages in the section
s = oRng.Fields(1).Result & " pages in the current section."
oRng.Fields(1).Delete
MsgBox s
s = "p1s1-p" & px & "s1" 'Added, format the value for the Pages
parameter
Application.PrintOut Pages:=s, Range:=wdPrintRangeOfPages 'Added,
print the desired pages

End Sub
 

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