Home > OS >  Returning the Line BEFORE a Table in Word
Returning the Line BEFORE a Table in Word

Time:11-17

I am trying to write an Excel VBA Script to extract data from 12 years worth of Trivia Sheets I have written in Word.

The result will be a big Excel file of Trivia Questions and Answers

I haven't Coded anything for SO LONG, but I'm getting there...

I want to Copy the text that Exists BEFORE a Table...

The titles are circled in yellow:

image

I can find the table well enough, but cannot come up with code to extract the Titles that are BEFORE... but not actually a PART of the Table...

Stu

Can anyone help?

CodePudding user response:

Assuming that there is no empty paragraph(s) between the table and the text, you can access that paragraph text by using the Previous method of the table's first paragraph like so:

'Assuming you have set the word document to the variable wordDoc
wordDoc.Tables(1).Range.Paragraphs(1).Previous.Range.Text
  • Related