Microsoft Developer Network > Forums Home > Microsoft ISV Community Center Forums > Visual Basic for Applications (VBA) > Hiding selected sections in Word Document based on string search
Ask a questionAsk a question
 

QuestionHiding selected sections in Word Document based on string search

  • Friday, October 30, 2009 10:06 AMkohare Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have very little experience of using Visual Basic with MS Word.

    I have a Word document and I wish to write a macro that will hide certain sections of the document depending on the result of a search of the section title. The section title always has a style Heading 4.

    The main problem I am having is how to select individula lines in the document. My initial thoughts are to perform this task using the following steps:

    Select the first line in the document.
    If line style is Heading 4
       Search for string within line
       If string is not present
          Select all lines until end of section
          Hide selected lines
       End if
    End if

    This will be repeated for the entire document.

    I am specifically looking for guidance on how to get the macro to select individual lines in the document and also on how to loop through the document as a whole.

    If there are any suggestions of an easier way to accomplish this task then they are also very welcome.

    Thanks
    • Moved byJeff ShanMSFTMonday, November 02, 2009 3:27 AMvba question (From:Visual Basic General)
    •  

All Replies