table value how to remove boxes

J

Jay Freedman

Yes, the box (and the invisible carriage return that makes it go to the
second line) is a character -- the cell marker, which appears as the symbol
¤ when you display nonprinting characters, and which actually consists of
the two characters Chr(13)+Chr(7).

The way to get rid of it depends a bit on how you're retrieving the value.
If you select the cell and grab Selection.Text (not recommended), do this to
exclude the cell marker from the selection:

Dim oTbl As Table
Dim myVariable As String
Set oTbl = ActiveDocument.Tables(1)

oTbl.Cell(2,3).Select
Selection.MoveEnd wdCharacter, -1
myVariable = Selection.Text

It's a better idea to use a Range object so you don't have to move the
Selection (which forces a screen redraw and also loses the user's place in
the document):

Dim oTbl As Table
Dim oRg As Range
Dim myVariable As String
Set oTbl = ActiveDocument.Tables(1)

Set oRg = oTbl.Cell(2, 3).Range
oRg.MoveEnd wdCharacter, -1
myVariable = oRg.Text

Alternatively, you can leave the Range set to the whole cell and then remove
_two_ characters from the end of the string:

Dim oTbl As Table
Dim oRg As Range
Dim myVariable As String
Set oTbl = ActiveDocument.Tables(1)

Set oRg = oTbl.Cell(2, 3).Range
myVariable = Left(oRg.Text, Len(oRg.Text) - 2)

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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