Get hold of a table within a textbox

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Get hold of a table within a textbox

Post by Robie »

Hi

Very stupid questions but I have two issues I need to solve - needing VBA access/

1. How can I access a table in a textbox in section 1 of a Word document? Using ActiveDocument.Shapes(1).select (which correctly picks the textbox) but Selection.tables(1) doesn't work. I don't need to select the textbox - as long as I can hold of the table/range within it.
2. Access textbox text in a header section 2? I need to change those for all documents and will be applied to all headers in the document(s)?

Thanks.

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Get hold of a table within a textbox

Post by HansV »

1. You can use

Code: Select all

    Dim tbl As Table
    Set tbl = ActiveDocument.Shapes(1).TextFrame.TextRange.Tables(1)
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Get hold of a table within a textbox

Post by HansV »

2. You can use

Code: Select all

    Dim tbl As Table
    Set tbl = ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary).Range.Tables(1)
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Get hold of a table within a textbox

Post by Robie »

Hmmm. Thank you Hans. That simple eh!

I thought I did it that way initially but was getting an error.
Thank you once again.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Get hold of a table within a textbox

Post by macropod »

Robie wrote:1. How can I access a table in a textbox in section 1 of a Word document? Using ActiveDocument.Shapes(1).select (which correctly picks the textbox) but Selection.tables(1) doesn't work. I don't need to select the textbox - as long as I can hold of the table/range within it.
Why is the table in a textbox? You can wrap text around a table without using a textbox.
Paul Edstein
[Fmr MS MVP - Word]

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Get hold of a table within a textbox

Post by Robie »

macropod wrote:
Robie wrote:1. How can I access a table in a textbox in section 1 of a Word document? Using ActiveDocument.Shapes(1).select (which correctly picks the textbox) but Selection.tables(1) doesn't work. I don't need to select the textbox - as long as I can hold of the table/range within it.
Why is the table in a textbox? You can wrap text around a table without using a textbox.
Don't ask me - my question too. I am just processing new company's documents which are designed this way. :hairout:

User avatar
StuartR
Administrator
Posts: 12604
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Get hold of a table within a textbox

Post by StuartR »

Try
Activedocument.Shapes(1).TextFrame.TextRange.Tables(1)
StuartR


Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Get hold of a table within a textbox

Post by Robie »

StuartR wrote:Try
Activedocument.Shapes(1).TextFrame.TextRange.Tables(1)
Thanks Stuart.