Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Step through document to make headers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ybazizi - 21 Mar 2005 02:11 GMT
I have a document that is about 600 pages long that I need to
programmatically make headers (Heading 1, Heading 2, Heading 3...)  I want to
be able to step through a document line by line and read the contents of the
beginning of each line, and if it matches a certain text, make that line a
header.  Is there any simple way I can use a loop to do this?

Thanks,

J
Greg Maxey - 21 Mar 2005 03:16 GMT
Not saying this is the best way, but something like this might do:

Sub Test()
Dim oPar As Paragraph

For Each oPar In ActiveDocument.Paragraphs
 If InStr(oPar.Range.Text, "Match this text") = 1 Then
   oPar.Style = "Heading 1"
 End If
 If InStr(oPar.Range.Text, "Match some other text") = 1 Then
   oPar.Style = "Heading 2"
 End If

Next oPar

End Sub

Replace "Match this text" and "Match some other text"  with the certain text
you had in mind.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> I have a document that is about 600 pages long that I need to
> programmatically make headers (Heading 1, Heading 2, Heading 3...)  I
[quoted text clipped - 6 lines]
>
> J
ybazizi - 21 Mar 2005 03:31 GMT
Thanks Greg - that was exactly what I needed.  I just needed a good example
of the way to use the Range object.

J

> Not saying this is the best way, but something like this might do:
>
[quoted text clipped - 26 lines]
> >
> > J

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.