Printing multiple "page 1's" of a document

K

Katy White

Hello,

I have a word document that is output from another program in RTF. At the
top of each page, there is a page number that is not in a header or anything
and is not a field, it's just text output. This document is not continuously
numbered from beginner to end, so there are several page 1s' in it. I need
to be able to scroll through the document and print each page that has "Page
1 of " on it. I have been looking at Find.Text = "" but I need to loop
through the document to the end and print each page that I need.

Can anyone help me out? Thanks!

Katy
 
D

Dave Lett

Hi Katy,

If your document using sections to handle the page numbering, then you can
use something like the following:

Dim iSec As Integer
Dim sPages As String
For iSec = 1 To ActiveDocument.Sections.Count
sPages = sPages & "p1s" & iSec & ","
Next iSec
ActiveDocument.PrintOut Range:=Left(sPages, Len(sPages) - 1)

However, it doesn't sound like the document is using sections. If you do a
find for "Page 1 of" does "Page 1 of" get selected. If so, you could use
something like the following:

With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Text = "Page 1 of"
Do While .Execute
ActiveDocument.PrintOut Range:=wdPrintCurrentPage
Loop
End With
End With

Hope these ideas get you started,

Dave
 
K

Katy White

Thanks Dave, I was mostly on the track of suggestion number 2 - works great
now!
 
G

Gilley

Katy,

I just went through the same process as you. I am putting my VB code below.

The main difference is that I was needing to insert a page break before each
instance of WELTON USA, LTD.

The code is pretty simple, but it took me a while to figure out the looping.
I hope you can use some of what I have done so you don't have to spend as
much time 'tinkering' as I did.

Dim iCount As Long
Dim strSearch As String

strSearch = "WELTON USA, LTD"
iCount = 0

With ActiveDocument.Content.Find
.Text = "WELTON USA, LTD"
.Format = False
.Wrap = wdFindStop
Do While .Execute
iCount = iCount + 1
Loop
End With

counter = 0
Do

With Selection.Find
.Text = "WELTON USA, LTD"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
'MsgBox (counter)
Selection.Find.Execute
If counter <> 0 Then

Selection.HomeKey unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak

End If
Selection.EndKey unit:=wdLine
End With
counter = counter + 1
Loop Until counter = iCount

Hope this helps,

Gilley
aka Dilbert
 

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