Reply
 
Thread Tools Display Modes
  #1   Report Post  
Bill Sturdevant
 
Posts: n/a
Default 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   Report Post  
Shauna Kelly
 
Posts: n/a
Default

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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Placing 1st table into a cell within 2nd table kathryngriffin1962 Tables 2 June 2nd 05 04:09 AM
Table headers/footers and layout Keith Page Layout 1 April 8th 05 07:37 PM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
word table cell resize or word table cell size change or word table change cell size [email protected] Tables 0 January 13th 05 09:55 PM
Table Cell not Centered Correctly (Too far left) Peter Reaper New Users 7 January 13th 05 05:54 PM


All times are GMT +1. The time now is 11:55 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"