Results 1 to 7 of 7
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Direct reference to Selection in other StoryRange? (Word 2002 SP-2)

    I'm not looking for workarounds here, since I can see plenty of those. I'm just posting in case there's a direct VBA property (or method) I'm not aware of.

    A Word document can have multiple Selections at a given moment -- one in each of several StoryRanges. For example, if you have a footer open in a split pane and move back and forth between the two StoryRanges, the previous Selection in each is maintained. My question is: Is there any direct way to refer to the current Selection in one of the non-active StoryRanges? For example, while a footer is the active StoryRange, can I set a range to the Selection in the MainTextStory (without making the MainTextStory active)?

    In case it occurs to anyone else to try it, I already (unsuccessfully) tried
    <pre> Set rngX = rngX.Document.StoryRanges(wdMainTextStory).Bookmar ks("Sel").Range</pre>

    There's no such bookmark ('member of collection doesn't exist") unless the MainTextStory is the active StoryRange.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Direct reference to Selection in other StoryRange? (Word 2002 SP-2)

    Word obviously keeps track of these selected ranges, but as far as I can see, this is not exposed in the object model.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Direct reference to Selection in other Ranges

    If you have used split panes to view the header or footer then the following code reveals the selected text in each pane.
    <pre>Sub temp1()
    Dim aPane As Pane
    For Each aPane In ActiveDocument.ActiveWindow.Panes
    Debug.Print aPane.Selection
    Next aPane
    End Sub</pre>

    Perhaps you can work with this to do what you require.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Direct reference to Selection in other Ranges

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Thanks for the tip!

    In Normal view, it looks like maybe I can always refer to the Selection in the MainTextStory (without worrying about whether it's active or not) like this:
    <pre> Set rngX = rngX.Document.ActiveWindow.Panes(1).Selection.Rang e</pre>

    Similarly, if Panes.Count is 2, I can refer to the Selection in the special pane by using Panes(2) rather than Panes(1). And if I Panes.Count is ever 3 (is that possible?), the heck with it.

    In Print Layout view I may be out of luck.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Direct reference to Selection in other Ranges

    Perhaps you could remember your current Range, go to the main document story to set rngX, and then return the selection to your old Range?

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  6. #6
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Direct reference to Selection in other Ranges

    Definitely a possibility, but I was wondering if there was a completely "clean" way that didn't require changing the Selection.

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Direct reference to Selection in other Ranges

    I don't have documentation of this, but I believe that Selection is always a property of a Pane object. In the case of ActiveWindow, Application or Global, the Selection property is derived implicitly from the ActivePane. If you read the development documentation for OpenOffice.org/StarOffice, you see a sharper divide between properties of documents themselves versus properties of views of documents presented by particular viewers. Microsoft isn't so explicit about that, but I have come to believe that a Range falls on the document side of this classification, while the Selection falls on the viewer side. Thus, it is not completely illogical that the "selection" in an "out of view" pane is unavailable. Okay, now I'm babbling. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •