Posts

Showing posts from February 3, 2019

Finding a “Heading” Style in a Word Document

Image
1 I have a Word macro that allows to put his/her cursor anywhere in a Word document and it finds and saves the Heading 1, Heading 2 and Heading 3 text that is above the text selected by the user in order capture the chapter, section and sub-section that is associated with any sentence in the document. I am currently using the code below which moves up the document line-by-line until it finds a style that contains "Heading x". When I have completed this task I move down the number of lines that I moved up to get to Heading 1, which may be many pages. As you can imagine this is awkward, takes a long time (sometimes 60+ seconds) and is visually disturbing. The code below is that subroutine that identifies the heading. Dim str_heading_txt, hdgn_STYLE As String Dim SELECTION_PG_NO as Integer