• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 774
  • Last Modified:

select table in word doc using vba

I wish to change the font size in a table that is embedded in a word doc using vba.  My question is:  

How do you select a table imbedded in a word doc with vba?
0
sander69
Asked:
sander69
  • 2
1 Solution
 
GrahamSkanCommented:
To find a table in VBA, it is best to know it's sequential number in the document:

Dim tbl as Table
Set tbl = ActiveDocument.Tables(3)
tbl.Range.Font.Size = 14

otherwise, you would have to know something about the table.

Of course you could always bookmark it,

    Dim tbl As Table
   
    Set tbl = ActiveDocument.Bookmarks("bmkThisTable").Range.Tables(1)
    tbl.Range.Font.Size = 8

0
 
sander69Author Commented:
Is there a way to loop through all of them?  I assume they are indexed in some manner.
0
 
GrahamSkanCommented:
Absolutely. The index is in the order that they appear on the document , i.e. a table's index will change if tables are added or deleted earlier in the document. However there is a Tables Collection, so if you can easily step through them all.

Dim tbl as Table
For each tbl in ActiveDocument.Tables
  tbl.Range.Font.Size = 14
Next tbl


0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now