Creating discontiguous selection programmatically

K

Ken Getz

I can see how to create a discontiguous selection in the UI, but although
I've tried, I can't figure out how to create one programmatically.
Essentially (this is just a small part of a complex issue), I really need to
REMOVE a chunk from a user's selection. That is, if in the SelectionChanged
event, I discover that a user has included a content control in the
selection, I need to remove the content control from the selection. So I
guess this boils down to:

* How can I remove a chunk of the user's selection from being selected?

or

* How can I recreate the selection, without including a particular chunk?

Is there a generalized solution for this? I was hoping that the Selection
class would have a collection of (subselections--I didn't see such an object
in the OM), but I sure can't find it in the Object Browser or documentation.

Many thanks! -- Ken
 
J

Jonathan West

Ken Getz said:
Never mind. I'm out of luck, apparently. Just found this:
http://support.microsoft.com/kb/288424. Unless someone knows that the
information in this article has changed for 2007, you simply can't do what
I need to do. Darn. -- Ken

As far as I know, it hasn't changed in 2007.

About the only way to go about this is to apply some otherwise unused font
property to the selection (Marching Red Ants is often used for the purpose.
You then use the Find object to find all the individual ranges that have
Marching Red Ants format, and check each range separately and do the
following

- see if it has a content control in it.

- If it doesn't, remove the marching Red Ants format, and then do whatever
else you needed to do

- If it does, remove the Marching Red Ants format, create two separate
Ranges, one either side of the content control, and do whatever you need to
on each individual range

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
K

Ken Getz

Very clever! Make use the Find method, which will get me all the separate
ranges! I will give this a try...

Appreciate the help -- Ken
 

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