Heading

F

Flint

Hello,

I need to locate a heading within a document, knowing only its text, not the
number -so I can't do, for example
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst, Count:=16,
Name:=""
- and then select all the text between this heading and the next.

Using "find" is no good, because there are plenty of parts in the document
where the text is found. So far, I have thought of selecting each one of them
and then looking at its style, but that seems to be a bit messy.

How can it be done some other way?

Thanks.
 
H

Helmut Weber

Hi Flint,

like this?

Sub Test400()
Dim rngDcm As Range
Set rngDcm = ActiveDocument.Range
With rngDcm.Find
.Text = "Thequickbrown"
.Style = "Heading 1"
If .Execute Then
rngDcm.Select
Selection.Bookmarks("\HeadingLevel").Select
Selection.start = Selection.start + _
Len(rngDcm.Paragraphs(1).Range)
End If
End With
End Sub

Gets the text between the first occurence of
"Thequickbrown" in a paragraph of style "Heading 1"
and the next paragraph of style "heading 1".


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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