Non contiguous ranges in word?

T

Tin P

Hi all,

I am writing a program in which I need to create a non contiguous
Range object in a word document. I believe that this is possible, as
it is possible to select non-contiguous ranges manually by holding
down the CTRL key. Does anyone know how to do this programatically?

Thanks in advance,

Tin
 
J

Jonathan West

Word VBA doesn't provide any support in the object model for the multiple
selections that you can do through the user interface.

However, in a word VBA macro you can define as many Range object variables
as you like (or even an array of them) and assign various ranges within the
document to these Range objects.
 
T

Tin P

Thanks.

This does't solve my problem, as looping through all of the ranges I
need takes too long. I need to set a property on a single range, for
efficiency reasons.

Cheers
Tin
 
J

Jonathan West

Tin P said:
Thanks.

This does't solve my problem, as looping through all of the ranges I
need takes too long. I need to set a property on a single range, for
efficiency reasons.

Tell me a bit more about these ranges and what you need to change. There may
be a different faster approach to the problem.
 
T

Tin P

Jonathan West said:
Tell me a bit more about these ranges and what you need to change. There may
be a different faster approach to the problem.

I am trying to set all the smart tags in a (very large) document to a
different colour. My code is in C++, here is the relevant part:


SmartTagsPtr stags = rng->GetSmartTags();
_DocumentPtr doc = rng->GetDocument();

for(int i = 1; i <= stags->Count; i++) {
SmartTagPtr stag = stags->Item(COleVariant((long)i));
RangePtr rng = stag->Range;
rng->GetFont()->PutColor((Word::WdColor)RGB(0,255,0));
}

It might help to know that I am recognising the smart tags myself.

Cheers

Tin
 

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