Home |
Search |
Today's Posts |
#1
|
|||
|
|||
How to check value of table cell in VB
I have some VB code that will loop through all tables in a document and
perform certain formatting functions on selected tables. To decide which are the selected tables I need to test a cell. How can I test the value of a cell? I have tried the following... Dim pCell As Word.Cell Dim pTable As Word.Table For Each pTable In ActiveDocument.Tables MsgBox pTable.Cell(2,1) 'This works If pTable.Cell(2, 1) = "MyValue" Then 'This does NOT work .... formatting instructions End If Next |
#2
|
|||
|
|||
Hi Bill
To retrieve the text from a table cell use something like pTable.Cell(2,1).Range.Text However, be aware that a table cell holds its text or other content plus the end-of-cell marker. That consists of two characters: chr(13) & chr(7). So if your table cell contained the text "Hi" then len(pTable.Cell(2,1).Range.Text) = 4. And pTable.Cell(2,1).Range.Text = "Hi" will be False. So you need to test bearing the end-of-cell marker in mind. Hope this helps. Shauna Kelly. Microsoft MVP. http://www.shaunakelly.com/word "Bill Sturdevant" wrote in message ... I have some VB code that will loop through all tables in a document and perform certain formatting functions on selected tables. To decide which are the selected tables I need to test a cell. How can I test the value of a cell? I have tried the following... Dim pCell As Word.Cell Dim pTable As Word.Table For Each pTable In ActiveDocument.Tables MsgBox pTable.Cell(2,1) 'This works If pTable.Cell(2, 1) = "MyValue" Then 'This does NOT work .... formatting instructions End If Next |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Placing 1st table into a cell within 2nd table | Tables | |||
Table headers/footers and layout | Page Layout | |||
Table AutoFormats vs. Table Styles confusion | Tables | |||
word table cell resize or word table cell size change or word table change cell size | Tables | |||
Table Cell not Centered Correctly (Too far left) | New Users |