Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

Retrieving text from a table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nirmal Singh - 07 Apr 2006 16:17 GMT
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
Greg - 07 Apr 2006 16:47 GMT
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
Nirmal Singh - 07 Apr 2006 16:58 GMT
>There are a couple of ways to strip the cell marker.  Here is one:
>
[quoted text clipped - 5 lines]
>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
Martin - 07 Apr 2006 18:30 GMT
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)

> I am using the following to retrieve the text from cell(5, 2)
>
[quoted text clipped - 6 lines]
>
> Nirmal
Doug Robbins - Word MVP - 09 Apr 2006 16:00 GMT
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.

Signature

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

>I am using the following to retrieve the text from cell(5, 2)
>
[quoted text clipped - 6 lines]
>
> Nirmal
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.