Retrieving text from a table cell

N

Nirmal Singh

I am using the following to retrieve the text from cell(5, 2)

ActiveDocument.Tables.Item(1).Cell(5,2).Range.Text

It is coming back with the text but with extra characters appended.
When the cell is blank it is coming back with three characters. I
presume this is partly the carriage return and linefeed, how can I
eliminate these?

Nirmal
 
G

Greg

Nirmal,

There are a couple of ways to strip the cell marker. Here is one:

Sub ScratchMacro()
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)
With oTbl
MsgBox Left(.Cell(5, 2).Range.Text, Len(.Cell(5, 2).Range.Text) - 2)
End With
End Sub
 
N

Nirmal Singh

There are a couple of ways to strip the cell marker. Here is one:

Sub ScratchMacro()
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)
With oTbl
MsgBox Left(.Cell(5, 2).Range.Text, Len(.Cell(5, 2).Range.Text) - 2)
End With
End Sub

Greg,

Thanks for that, I was just wondering if there was anything built into
Word to ignore these cell markers?

Nirmal
 
M

Martin

This ain't elegant but works (you may need to fiddle the number at the end):

Left(ActiveDocument.Tables.Item(1).Cell(5, 2).Range.Text, _
Len(ActiveDocument.Tables.Item(1).Cell(5, 2).Range.Text) - 2)
 
D

Doug Robbins - Word MVP

Dim myrange as Range
Set myrange = ActiveDocument.Tables(1).Cell(5,2).Range
myrange.End = myrange.End - 1

myrange will now contain just the text from the cell without the end-of-cell
marker.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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