Special Character at End of Each Table Cell

C

CoxProg

I am trying to test the contents of cells in a table. However, th
special character found in each table cell throws me off. I have som
options of getting around it (described below), but are there any othe
suggestions on how to work around this?

Here is my simplified code:

Dim TextToTest As String

TextToTest = ActiveDocument.Tables(1).Cell(Row:=1
Column:=1).Range.Text

If TextToTest = "Sought Value" Then
MsgBox "True"
Else
MsgBox "False"
End If

My result is always "False." When I look at the extracted value o
TextToTest on a cell that contains "Sought Value", I get:

Sought Value
(the next line contains a bullet looking thing that this window will no
let me paste into it)

That pesky character! :) I have rigged some ways around it b
calculating the length of the TextToTest (x) and then extracting x-
characters from the left.

But I am looking for an option that references that special characte
directly. Different threads suggest the special character is "^10" o
"^008" but my tests for those characters didn't seem to work.

Thanks in advance!
 
S

Suzanne S. Barnhill

The character is the end-of-cell mark, which holds the formatting for the
cell and also functions for the paragraph mark for the last (or only)
paragraph in a cell. Word doesn't, apparently, provide any way to address it
directly.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
S

Stefan Blom

As Suzanne wrote, I don't think there is a way to work with the end-of-cell
mark directly. I'm not even sure it would be useful, if it was possible. As
you have noticed, a workaround is required.

You have been removing the final character of the string. The alternative is
to work with a range object from which you remove the final character (by
redefining the range). For example:

Sub MyTestSub()
Dim r As Range
Set r = ActiveDocument.Tables(1).Cell(1, 1).Range.Duplicate
If r.End > r.Start Then
r.End = r.End - 1

End If

' more code follows...
End Sub

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"CoxProg" wrote in message

I am trying to test the contents of cells in a table. However, the
special character found in each table cell throws me off. I have some
options of getting around it (described below), but are there any other
suggestions on how to work around this?

Here is my simplified code:

Dim TextToTest As String

TextToTest = ActiveDocument.Tables(1).Cell(Row:=1,
Column:=1).Range.Text

If TextToTest = "Sought Value" Then
MsgBox "True"
Else
MsgBox "False"
End If

My result is always "False." When I look at the extracted value of
TextToTest on a cell that contains "Sought Value", I get:

Sought Value
(the next line contains a bullet looking thing that this window will not
let me paste into it)

That pesky character! :) I have rigged some ways around it by
calculating the length of the TextToTest (x) and then extracting x-2
characters from the left.

But I am looking for an option that references that special character
directly. Different threads suggest the special character is "^10" or
"^008" but my tests for those characters didn't seem to work.

Thanks in advance!

 

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