Multiple non-contiguous selections

  • Thread starter concentratedawesome
  • Start date
C

concentratedawesome

I'd like to use the PIAs to set the document selection to include multiple
non-connected ranges throughout my document. I know you can do this by using
the ctrl key in Word, but will someone please tell me how to do it with the
Interop libs.
 
J

Jay Freedman

concentratedawesome said:
I'd like to use the PIAs to set the document selection to include
multiple non-connected ranges throughout my document. I know you can
do this by using the ctrl key in Word, but will someone please tell
me how to do it with the Interop libs.

It isn't possible in the VBA that's built into Word
(http://support.microsoft.com/?kbid=288424), so I doubt that it's possible
through the PIAs either.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
C

concentratedawesome

Thanks Jay. Dude, I wonder if I could .Select() one range and then use
WinAPI SendInput to like hold down the Ctrl button and then do .Select() on
another range. Man, that would be awesome. Sounds like a blog post that an
MVP would do to show off...
 
F

fumei via OfficeKB.com

"then do .Select() on another range"

and how exactly would you do that?

The Range object does not allow non-contiguous ranges within VBA. It has ONE
.Start and ONE .End property.

Even if you use Ctrl and select non-contiguous areas (ranges) ANY action via
code (VBA) will only action against the last range. The other oarts are
ignored.

Yes, you can action non-contiguous selected ranges in the GUI, but you can
NOT do so in VBA - even if non-contiguous ranges are in fact selected with
Ctrl.
Thanks Jay. Dude, I wonder if I could .Select() one range and then use
WinAPI SendInput to like hold down the Ctrl button and then do .Select() on
another range. Man, that would be awesome. Sounds like a blog post that an
MVP would do to show off...
[quoted text clipped - 4 lines]
(http://support.microsoft.com/?kbid=288424), so I doubt that it's possible
through the PIAs either.
 
J

Jonathan West

fumei via OfficeKB.com said:
"then do .Select() on another range"

and how exactly would you do that?

The Range object does not allow non-contiguous ranges within VBA. It has
ONE
Start and ONE .End property.

Even if you use Ctrl and select non-contiguous areas (ranges) ANY action
via
code (VBA) will only action against the last range. The other oarts are
ignored.

Yes, you can action non-contiguous selected ranges in the GUI, but you can
NOT do so in VBA - even if non-contiguous ranges are in fact selected with
Ctrl.

Not true. There is no way that I know of through VBA to make multiple
selections, but if multiple selections have already been made, some VBA
commands will act on all the selections at once. This is an example

Selection.Font.Animation = wdAnimationMarchingRedAnts

If you want to do something more sophisticated on multiple selections, you
can start out by applying some otherwise-unused format such as marching red
ants animation. You can then use the Find method to find all bits of text
with that formatting and assign each piece to an element in an array of
Range objects. You can then process each Range object in turn in whatever
way you want.
 
C

concentratedawesome

1) You do range1.Select()
2) SendInput() for the Ctrl key
3) range2.Select()

yes, I know, the range2.Select() MAY deselect range1.Select(), but maybe it
won't because it thinks that the ctrl key is down. Y'all haven't tried it so
you can't really say for sure. I know that I'm mixing UI and PIA
functionality here, but maybe they don't operate completely independently of
one another.

fumei via OfficeKB.com said:
"then do .Select() on another range"

and how exactly would you do that?

The Range object does not allow non-contiguous ranges within VBA. It has ONE
.Start and ONE .End property.

Even if you use Ctrl and select non-contiguous areas (ranges) ANY action via
code (VBA) will only action against the last range. The other oarts are
ignored.

Yes, you can action non-contiguous selected ranges in the GUI, but you can
NOT do so in VBA - even if non-contiguous ranges are in fact selected with
Ctrl.
Thanks Jay. Dude, I wonder if I could .Select() one range and then use
WinAPI SendInput to like hold down the Ctrl button and then do .Select() on
another range. Man, that would be awesome. Sounds like a blog post that an
MVP would do to show off...
I'd like to use the PIAs to set the document selection to include
multiple non-connected ranges throughout my document. I know you can
[quoted text clipped - 4 lines]
(http://support.microsoft.com/?kbid=288424), so I doubt that it's possible
through the PIAs either.
 
C

concentratedawesome

I rodger that, but my goal is just to highlight the areas on the screen with
the selection style. I don't like assigning styles in the document because I
don't want them hanging around in the document when the user is working with
it. What I'm trying to do is validate the document content and point out
multiple errors in the document.
 

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