Text of first paragraph that has been formatted with a user definedheading style to be displayed in

A

andreas

Dear Experts:

Below macro checks whether a user-defined heading style (Heading_IV)
has been applied. If so, it shows the section number of the first
occurence of the custom-defined heading style (Heading_IV) as well as
the corresponding page number of the first occurrence.

It is working fine.

BUT I also would like the MsgBox to show me
.... (1) the text of the first occurrence of this user-definded
heading style (Heading_IV) and ...
.... (2) the paragraph number of the first occurence of this user-
defined heading style (the counting to begin from the section where
the first occurrence of the user-defined heading style has occurred)

Help is very much appreciated. Thank you very much in advance.

Kind Regards, Andreas


Sub FirstOccurrenceUserDefinedHeaderStyle()

Dim rng As range
Dim oRange_Heading_IV As range
Dim nSection_Heading_IV As Long
Dim iPageStart As Integer

Set rng = ActiveDocument.range
With rng.Find
.Style = ActiveDocument.Styles("Heading_IV")
.Forward = True
.Wrap = wdFindStop
.Format = True

If .Execute() Then
iPageStart = rng.Information(wdActiveEndPageNumber)
Set oRange_Heading_IV = rng
nSection_Heading_IV = rng.Sections(1).Index
MsgBox "The first occurrence of HeadingIVis found on
page " & iPageStart & " and Section " & Section_Heading_IV & "."
......
......
 
D

Doug Robbins - Word MVP

oRange_Heading_IV.Text or rng.Text will show what you want

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

andreas

oRange_Heading_IV.Text or rng.Text will show what you want

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP















- Show quoted text -

Hey Dough,

thank you very much for your quick help. It works. Great! I wonder
whether you also could give me some help with my second requirement on
that macro:

.... (2) the paragraph number of the first occurence of this user-
defined heading style (the counting of the paragraph number to begin
from the section where
the first occurrence of the user-defined heading style has occurred)

Thank you vey much in advance. Regards, Andreas
 

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