1
votes

I'm looking for a way to store a reference to a selection. It seems that I create a variable such as:

dim tSelect as Selection
Set tSelect = Selection

And I create a reference to the active selection object. If I change selection WITHOUT running any code (for instance, during a DoEvents type loop) the selection variable updates without calling:

Set tSelect = Selection

I need to create a variable that will hold a static reference to what is selected, then I need to be able to change selection without losing the reference to the previously selected text.

The Range object wont work. I need to be able to select a list of paragraphs using the ctrl key that are not necessarily near each other.

When using this method to select paragraphs, the selection object only shows the last "group" of paragraphs (for instance, if I select 1 paragraph, skip the next one and use ctrl+click to select 2 more, the range/selection objects only point at the last 2).

The following does not work either (for admittedly obvious reasons):

set tSelect = new selection

Any ideas would be greatly apreciated.

1

1 Answers

1
votes

According to microsoft, this problem will have great difficulties.
http://support.microsoft.com/kb/288424

The best solution I can think of is changing the style of the text to something unique in the file, then search the file and create a collection of subranges for the unique text. Once you have the collection of subranges you can change the style back to normal.

In the link above, it says that you can not use vba to select multiple ranges. Which means that you'll have to use vba code to loop through the collection of sub ranges whenever you want to perform an action.

In recap, Storing:

  1. Make text unique with one of the properties that does work with discontinguous selections
  2. Loop through file, find chunks of unique text and store them as separate ranges in a collection
  3. Loop through collection and make text normal again

Performing an action:

  1. loop through collection of sub ranges
  2. perform action on each subrange