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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Direct reference to Selection in other StoryRange? (Word 2002 SP-2)

    Author
    Topic
    #416870

    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

        Set rngX = rngX.Document.StoryRanges(wdMainTextStory).Bookmarks("Sel").Range

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

    Viewing 1 reply thread
    Author
    Replies
    • #933687

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

    • #933696

      If you have used split panes to view the header or footer then the following code reveals the selected text in each pane.

      Sub temp1()
        Dim aPane As Pane
        For Each aPane In ActiveDocument.ActiveWindow.Panes
          Debug.Print aPane.Selection
        Next aPane
      End Sub

      Perhaps you can work with this to do what you require.

      • #933716

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

            Set rngX = rngX.Document.ActiveWindow.Panes(1).Selection.Range

        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.

        • #933942

          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?

          cheers Klaus

          • #933980

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

            • #934521

              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. grin

    Viewing 1 reply thread
    Reply To: Direct reference to Selection in other StoryRange? (Word 2002 SP-2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: