why selection not an activedoc object

D

Dan

This is more of a curiosity than anything else. Why isn't "selection" an
object or property of the ActiveDocument? It seems like it should be, but I
only find it under the Application object?
Dan
 
K

Klaus Linke

Dan said:
This is more of a curiosity than anything else. Why isn't "selection"
an object or property of the ActiveDocument? It seems like it should be,
but I only find it under the Application object?


Hi Dan,

You can also find it under ActiveDocument.ActiveWindow.ActivePane.
My guess is that a lot of complexity is hidden here.

You can have several docs open and each "remembers" its Selection if you
activate it... Same with selections done in different panes of the same
document if you switch between panes.

The help seems a bit misleading: It claims that there can only be one
Selection object in the application (... which may explain why you found it
there in the Object Model).

But I can select say the letter "a" in one pane, "b" in another, and
retrieve the text of both:
? ActiveDocument.ActiveWindow.Panes(1).Selection.Text
a
? ActiveDocument.ActiveWindow.Panes(2).Selection.Text
b

That doesn't quite answer your question... Just my 2¢
Klaus
 
K

Klaus Linke

I just saw that the help on the Selection object has example code for
addressing selections done in different documents:

With Documents(1)
.Paragraphs.Last.Range.Select
.ActiveWindow.Selection.Cut
End With

With Documents(2).ActiveWindow.Selection
.StartOf Unit:=wdStory, Extend:=wdMove
.Paste
End With

In macros I've written in the past to copy/paste things between documents,
I've used Documents(#).Activate, and then worked with an unqualified
Selection (.Copy ...).
Turns out it can be done more elegantly, so I've learned something new.

:) 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