Extra characters in Rng.txt compared to Rng

J

Jay

In Word 97, I've accessed the text of a range I've defined using
Rng.Text. This works fine, but there are sometimes more characters in
the text than there are in the range. This occurs if I have a table,
for instance, where an empty cell or an end of row is represented by
one character in the range but two characters in the text string. It
also occurs if there's some autoshapes present in the document. This
causes problems to me since I'm using the VB function InStr() on the
text string, but need to find the position of my search string in the
range. How do I get around this problem?
 
D

Dave Lett

Hi Jay,

This is expected. Every cell has and "end of cell character", which is
actually two characters. If memory serves (and I'm not sure that it is right
now), the two characters are Chr(7) and Chr(13). You can always to a For
each Character in an empty cell to find out exactly which characters they
are, if that's important to you.

HTH,
Dave
 
J

Jay

Thanks Dave. I'm not concerned about what the extra characters are,
but how to map between the range characters and the text characters.
 
D

Dave Lett

Hi Jay,

I think you're asking how to return only the text in a cell. You can move
the end of the range backwards by one, as shown in the follwing example:

Dim oRng As Range
Dim oTbl As Table
Dim oCl As Cell
Set oTbl = ActiveDocument.Tables(1)
Set oCl = oTbl.Cell(1, 1)
Set oRng = oCl.Range
oRng.MoveEnd Unit:=wdCharacter, Count:=-1
Debug.Print Chr(34) & oRng.Text & Chr(34)

Hope this answers your question/solves your problem,
Dave
 

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