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 & "." ..... .....
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 "andreas" wrote in message news:e9036789-a99c-402a-8b83-749fd87f87f4@l64g2000hse.googlegroups.com... > 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 & "." > ..... > .....
On Sep 29, 4:35 am, "Doug Robbins - Word MVP" wrote: > 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 > > "andreas" wrote in message > > news:e9036789-a99c-402a-8b83-749fd87f87f4@l64g2000hse.googlegroups.com... > > > > > 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 & "." > > ..... > > .....- Hide quoted text - > > - 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