Checking characters in a range is too slow

J

Jean Ryckebosch

Hi,

I want to extract ranges from a paragraph which have the same
color. At the moment I solve this problem iterating over all characters in a
paragraph and comparing their color. Groups of consecutive characters with
the same formatting build a range. The result is a list of these ranges. (eg
from character 1 to character 8, the color is red, from character 9 to
character 11 the color is white, ...)

But as you might know, this is too slow because of the Collection iteration
(doing characters(i) for each and every character in the pragraph is way too
slow). I think it must be possible to do something with Find and Replace but
I am not sure how to start.

Thanks,

Jean
 
H

Helmut Weber

Hi Jean,
what colors?
Just some ordinary like wdColorSkyBlue,
all all possible colors?
 
K

Klaus Linke

Hi Jean,

"Find" would probably work fastest.

A bit simpler to program: Use the built-in "SelectCurrentColor".

Do
Selection.SelectCurrentColor
MsgBox Selection.Font.Color,,"Color:"
Selection.Collapse (wdCollapseEnd)
Loop While Selection.End < ActiveDocument.Content.End - 1

Regards,
Klaus
 

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