View Single Post
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

On Wed, 6 Apr 2005 14:56:06 +0200, "Robix"
wrote:

Hi,

I am writing macro that changes the color of the part of the text. For
determining the start and end position I use the InStr function. Text is in
the table. The returned value of the InStr function is correct only for the
cell(1,1). As soon as it moves to the next cell, the returned value
(character position) is different from the real one (it is one more than it
should be in the cell(1,2)). This difference increases as it moves from one
cell to another.

Can someone help me with this?

Thank you very much in advance.
Regards,
Robert



Hi Robert,

The InStr function counts all the characters in a string, including
the nonprinting ones. For instance, each end-of-cell mark (which
appears as ¤ when you display nonprinting characters) occupies two
characters in the document.

In any case, stepping though the cells one at a time is extremely
inefficient. You're usually better off with a Replace operation, which
can be used just to change formatting if you choose. Tell us more
about how you decide which text to recolor, and we can suggest a
better way to program it.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org