Chapter Number/Title Associated with Search Question 
Author Message
 Chapter Number/Title Associated with Search Question

This may too complex to answer, but I'll ask it anyway.

Within a Word document using VBA code, I know how to search for a character
string (which I figured how to do using Record Macro).  But now I need to
determine the chapter number and title associated with that string.

Is there an easy way to do this?  Or, can someone tell me how to approach
this?  (I believe somehow I need to step backwards and check if it is a
Heading style, but I don't know exactly how to do that.)



Fri, 08 Apr 2005 09:54:15 GMT  
 Chapter Number/Title Associated with Search Question
Hi Steve,

A macro that searches for every Heading 1 formatted paragraph in the document and gets the text and listnumber could look like this:

-----------------------------------------------------------
Sub FindHeadingStyle()

  Selection.HomeKey wdStory
  'get rid of any previous format criteria in the find dialog
  Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting

  With Selection.Find
    .Style = ActiveDocument.Styles(wdStyleHeading1)
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With

  Do While Selection.Find.Execute()
    'Show Text & number
    MsgBox Selection.Paragraphs(1).Range.Text & _
                  Selection.Paragraphs(1).Range.ListFormat.ListString
    Selection.Collapse wdCollapseEnd
  Loop

End Sub
-----------------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/


Quote:
> This may too complex to answer, but I'll ask it anyway.

> Within a Word document using VBA code, I know how to search for a character
> string (which I figured how to do using Record Macro).  But now I need to
> determine the chapter number and title associated with that string.

> Is there an easy way to do this?  Or, can someone tell me how to approach
> this?  (I believe somehow I need to step backwards and check if it is a
> Heading style, but I don't know exactly how to do that.)



Sat, 09 Apr 2005 09:08:23 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Number Search and Heading Style Search Questions

2. Macro to Write Chapter Title into Primary Header

3. Odd Numbered Chapter Pages

4. Generating Page Numbers for Chapters

5. No icons associated with the Title in the taskbar

6. Associating Number/Text Fields

7. Search results in vb.net do not have titles

8. Title tag search and replace

9. Search a particular Window from an incomplete windows title

10. Question: can you create a .exe application using VBA associated to Office97

11. get title (job title) information from global address list

12. Setting Font Size of Chart Title and axis title

 

 
Powered by phpBB® Forum Software