Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Paragraph Number and Text accessed from a Table?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe HM - 13 Oct 2006 12:26 GMT
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 extract the "3.1" and "Blah 1" when lTable is Table 1 in the
loop above.

Is there an easy way to do that?

Thanks!
Joe
Jonathan West - 13 Oct 2006 13:33 GMT
I'm not sure what you mean. A table contains paragraphs and text, not the
other way round. Do you mean the number and text of the heading immediately
above the table?

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

> Hello -
>
[quoted text clipped - 26 lines]
> Thanks!
> Joe
Joe HM - 13 Oct 2006 13:55 GMT
Hello -

Sorry I was not clear enough.  Yes ... I need to loop through all
tables and determine which section they are contained in ... as you
said ... the heading immediately above the table.

Thanks,
Joe

> I'm not sure what you mean. A table contains paragraphs and text, not the
> other way round. Do you mean the number and text of the heading immediately
[quoted text clipped - 36 lines]
> > Thanks!
> > Joe
Jonathan West - 15 Oct 2006 19:36 GMT
> Hello -
>
> Sorry I was not clear enough.  Yes ... I need to loop through all
> tables and determine which section they are contained in ... as you
> said ... the heading immediately above the table.

Try this

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

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Joe HM - 16 Oct 2006 18:06 GMT
Awesome ... thanks a lot!

I am trying to understand what this code is doing and wondering how I
could access the next-highest heading information - e.g. table is
contained in 3.2.1 and I would like to get the heading text of 3.2?

Thanks!
Joe

> > Hello -
> >
[quoted text clipped - 20 lines]
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Jonathan West - 17 Oct 2006 00:27 GMT
> Awesome ... thanks a lot!
>
> I am trying to understand what this code is doing and wondering how I
> could access the next-highest heading information - e.g. table is
> contained in 3.2.1 and I would like to get the heading text of 3.2?

They key to this is understanding what the \HeadingLevel bookmark does.
Wherever the current selection is, the \HeadingLevel bookmark stretches from
the heading paragraph above the selection (or including the selection, if
the selection is itself in a heading) to just above the next heading of the
same level.

Therefore, if you have found a third-level heading, and you want to find
it's parent 2nd-level heading, all you need do is position the selection
just in front of the start of the \Headinglevel bookmark, and then see where
it now reaches. It will wither reach to the previous 3rd-level heading, or
to the parent 2nd-level heading. You repeat this process until you reach the
2nd-level heading.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Joe HM - 17 Oct 2006 13:04 GMT
Hello -

Thanks so much for all the information ... that helped me a ton!

Joe

> > Awesome ... thanks a lot!
> >
[quoted text clipped - 21 lines]
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.