none
Iterating through Word document RRS feed

  • Question

  • Given that Word objects (Paragraphs, Comments, Tables, Figures...) exist as sequenced (indexed) collections and each collection can be iterated in VB/A with For Each ... how does one iterate through the sequence of objects contained in the ActiveDocument? For example a simple document may look like Headingstyle(1), Paragraph(1), Paragraph(2), Figure(1), Paragraph(3), Table(1), Paragraph(4), Figure(2)... 

    Is there an indexed collection of objects? Viz: Object(1).Type = Headingstyle,  Object(2).Type = Paragraph, Object(3).Type = Paragraph, Object(4).Type = Figure ... Or, even some construct that could dereference Object(396).Type = Table(13)

    Thanks

    Monday, July 25, 2011 9:40 PM

Answers

  • No, Word has nothing like this.

    Closest you could get would be to pick up the document in its WordProcessingML or WordOpenXML version and parse through that.

    You'll find more about Word's XML vocabularies at OpenxMLDeveloper.org


    Cindy Meister, VSTO/Word MVP
    Tuesday, July 26, 2011 6:56 AM
    Moderator