Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word: No of columns in row?

Status
Not open for further replies.

ShaneBrennan

Programmer
May 19, 1999
198
GB
Hi Everyone

Does anyone know how to detect/count how many columns there are in the currently selected row in a Word table?

I need to detect how many columns are in a table so I can decide to enter info into a 3 column table or 2 columns?

Thank you in advance for any help given.

Shane Brennan


 


Hi,

Check out the Table & Columns Objects in VB Help

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Could be tricky. I think a colleague tried to do the same thing but the problem is that because you can merge cells vertically and horizontally it's very difficult to say how many rows and columns a table actually has. It might be obvious if you draw a 3x3 table that it has 3 rows and 3 columns but if you merge all the cells on the first row to make a title area then does the first row have 1 column or 3?

You'll notice that in Word you can insert a table with specific starting dimensions but after that there isn't a table 'editor' per se. You can add rows and columns but you can't change the dimensions using the same method you used to add it in the first place, which is related to the reason above.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 


If you did this...
Code:
Sub test()
    Dim r As Row
    With ThisDocument.Tables(1)
        For Each r In .Rows
            MsgBox r.Cells.Count
        Next
    End With
End Sub
AND had vertically merged cells, you would get an error message on the FOR statement.

Otherwise you get a column count for each row.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top