Isolating Text of a Particular Size and Font

K

Kevin

I've got what I think are some simple questions. I'd appreciate any
help.

I have a pretty long word doc that is output from OCR recognition of a
help file for Windows Movie Maker. I'd like to make a table of
contents for the printed version. The formatting is constant, so
here's what I'd like my VBA procedure to do:

1.) Find every instance of Times New Roman size 23
2.) When each instance is found:
a.) Place the string of text into a new document
b.) Go up in the current document until the phrase "Movie Maker
Page x of 177" is found.
c.) Place the number from "x" above next to the exported string of
text from above.
3.) Start a new line in the new document, and repeat.

I'm guessing this is hard to visualize without seeing the doc that I'm
working with. So I'll try to give my best description of it. I was
asked to print a copy of the help file for Windows Movie Maker, and
create a table of contents for my printed file. I printed the help
file first with the Document Imager in Office 2003, and then sent that
document to my printer.

The imager created a document that was 177 pages long, and numbered it
across the top, much like a print out from IE. I used the OCR in the
MDI viewer to export the text to Word, and every subject heading came
out in Times New Roman size 23. Basically I want to find each heading,
and then go up the document until the line that says what page it was
on is found, and then put both of those in a new doc.

I'm sort of familiar with VBA (but for Excel, not Word!), so if you all
could point me to some functions in Word I could use or things that
might help, I'd really appreciate it! Thanks!

- Kevin
 
J

Jezebel

First, set up your document so that its pages match the 'Page x of 177' so
that Word's x matches the displayed x (you might need to set the initial
page number by hand). That way you can use the .Information() property to
determine the page number, instead of needing the second search.

Use code along these lines --

Dim pCount As Long
Dim pRange As Word.Range
Dim pOutput As Word.Document

Set pRange = ActiveDocument.Content
Set pOutput = Documents.Add

With pRange.Find
.ClearFormatting
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Name = "Times New Roman"
.Font.Size = 23

Do While .Execute
pOutput.Content.InsertAfter pRange & vbTab &
pRange.Information(wdActiveEndPageNumber) & vbCr
Loop

End With
 

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