开发者

Determine number of columns in a table in Word using VBA

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 i开发者_StackOverflows 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.


A table object knows how many columns it has, just check the Columns.Count property.

ThisDocument.Tables(1).Columns.Count


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜