Paragraph Number and Text accessed from a Table?

J

Joe HM

Hello -

I have a loop that steps through all tables of a document ...

For Each lTable In ActiveDocument.Tables
...
Next lTable

How can I determine the Paragraph Number and Paragraph Text that
contains the table?

Here is an example ...


3.1 Blah 1
Text ...
Table 1
More Text ...

3.2 Blah 2
Text ...
Table 2
More Text ...

I need to loop through all tables and determine under hich heading they
are - i.e. the heading immediately above the table (e.g. "3.1" and
"Blah 1" when lTable is Table 1).

Is there an easy way to do that?

Thanks!
Joe
 
S

Stefan Blom

If you are trying to reference the current Heading 2 paragraph, you
can use a STYLEREF field: { STYLEREF 2 \s }. Do the following to
insert it: Press Ctrl+F9; Word adds the field delimiters, {}. Type the
code as shown. Press F9 to update the field.

Note that you can have Word include a particular heading level in your
table captions. Just choose Insert | Reference | Caption. In the
Caption dialog box, choose "Table" for "Label." Click the Numbering
button. Enable the "Include chapter number" option and choose the
desired numbering level. Click OK twice.

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 
J

Joe HM

Hello -

Thanks for your help. I was actually looking for VBA code to do this
via a macro but your comments are also very helpful as I have to do
something within the document as well.

Here is the VBA code somebody posted at
microsoft.public.word.programming ...

Dim oTable as Table
Dim oHeading as Range

For Each oTable in ActiveDocument.Tables
oTable.Range.Select
Set oHeading =
ActiveDocument.Bookmarks("\HeadingLevel").Range.Paragraphs.First.Range
Debug.Print oHeading.ListFormat.ListString, oHeading.Text
Next oTable

Thanks again ...
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top