Reputation: 5129
just a quick question. I've got this table in a Word template which have two columns by default. Then I've got this button the user can press if he wants another column. The macro run inserts several text placeholders and formats certain things automatically. But what I want is some sort of routine which basically checks the number of columns in this table, and if there are two columns, the text typed in is automatically "Column 3" and if there are three columns there, the text should be "Column 4". Should be pretty simple if I can just find out how I can find the number of columns.
Upvotes: 0
Views: 15118
Reputation: 9548
A table object knows how many columns it has, just check the Columns.Count property.
ThisDocument.Tables(1).Columns.Count
Upvotes: 2
Reputation: 29153
This works:
Sub CountColumns()
Dim d As Document
Set d = ActiveDocument
Dim t As Table
Set t = d.Tables(1)
Debug.Print t.Columns.Count
End Sub
Upvotes: 1