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.
Get hold of a table within a textbox
-
- 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
1. You can use
Code: Select all
Dim tbl As Table
Set tbl = ActiveDocument.Shapes(1).TextFrame.TextRange.Tables(1)
Best wishes,
Hans
Hans
-
- 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
2. You can use
Code: Select all
Dim tbl As Table
Set tbl = ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary).Range.Tables(1)
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Get hold of a table within a textbox
Hmmm. Thank you Hans. That simple eh!
I thought I did it that way initially but was getting an error.
Thank you once again.
I thought I did it that way initially but was getting an error.
Thank you once again.
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Get hold of a table within a textbox
Why is the table in a textbox? You can wrap text around a table without using a textbox.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.
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Get hold of a table within a textbox
Don't ask me - my question too. I am just processing new company's documents which are designed this way.macropod wrote:Why is the table in a textbox? You can wrap text around a table without using a textbox.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.
-
- Administrator
- Posts: 12604
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Get hold of a table within a textbox
Try
Activedocument.Shapes(1).TextFrame.TextRange.Tables(1)
Activedocument.Shapes(1).TextFrame.TextRange.Tables(1)
StuartR
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Get hold of a table within a textbox
Thanks Stuart.StuartR wrote:Try
Activedocument.Shapes(1).TextFrame.TextRange.Tables(1)