Table cell attributes

M

Mystery Man

Can I programattically get the attributes of each cell of a word
table, eg alignment, font, size, colour etc?

eg something like the following?

Table.Cell(1,1).Font
Table.Cell(1,1).Alignment
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

You can get/set the attributes of the .Range of the cell. If the .Range
contains more than one paragraph, you would need to check the attributes of
the .Range of each paragraph.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
M

Mark Tangard

Many things we normally describe as attributes of a cell are actually
attributes of its *range*:

[table object].Cell(1, 1).Range.Font.Name
[table object].Cell(1, 1).Range.Font.Size
[table object].Cell(1, 1).Range.ParagraphFormat.Alignment

but in other cases:

[table object].Cell(1, 1).Range.VerticalAlignment
[table object].Cell(1, 1).Borders(wdBorderTop).LineWidth

Note also that some attributes ("properties") in VBA aren't returned in
a way you can immediately figure out. For example, this code:

Dim t as Table
Set t = ActiveDocument.Tables(1)
MsgBox t.Cell(1, 1).VerticalAlignment

isn't gonna spit out "Bottom" or "Centered," etc. It returns an integer
corresponding to the literal *constant* (those "wd-" prefixed things)
that you'd use if you were setting the attribute rather than returning it:

t.Cell(1, 1).VerticalAlignment = wdCellAlignVerticalCenter

So if you need your macro to talk to you in English, you need to mess
around with the way it speaks:

Dim c As Cell, xAtt As String
Set c = ActiveDocument.Tables(1).Cell(1, 1)
Select Case c.VerticalAlignment
Case wdCellAlignVerticalCenter
xAtt = "center"
Case wdCellAlignVerticalTop
xAtt = "top"
Case wdCellAlignVerticalBottom
xAtt = "bottom"
End Select
MsgBox "The cell is " & xAtt & "-aligned."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top