Results 1 to 11 of 11
  1. #1
    New Lounger
    Join Date
    Nov 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macros in Active Windows (Word 97)

    Hi, everybody --

    I have two questions that both have to do with active windows in VBA macros.

    I've got a macros that tile two windows vertically rather than horizontally in Word 97, which does not offer that choice natively. (They were not written by me and I don't understand the details of them.) You have to run "Window-ArrangeAll" before the macro will work, but after that it does in fact tile the files vertically. But it has a flaw that I don't understand, and I have one other logistical question.

    The flaw is that the two windows don't behave like ordinary windows in that when you get to the bottom of them there is no scrolling. You can scroll with the vertical scroll bar, and _sometimes_ you can scroll with the Word scrolling commands, but there is no automatic scrolling of the text when you get to the bottom of the window. You can keep typing, and the new text is entered, but you can't see it. I tried turning off the status bar and moving the Windows taskbar to see if that reactivated the bottom of the screen, but it didn't help.

    The second question has to do with what happens when a window is activated. In order to use these windows efficiently, text has to be zoomed down to 75%; that way you can see the whole page with no horizontal scrolling. I tried to make a macro that would zoom both files with one click. Zoom the first one, move to the next window, and zoom the second one. This works fine when you do it from the keyboard with the Zoom and Next Window commands. But when I recorded exactly the same keystrokes, what happened when I ran the macro was that one window gets zoomed, and I get an error message:

    Run-time error '91':
    Object variable or With block variable not set.

    Here's what gets recorded when I go through the procedure step-by-step exactly as I would do it manually:

    ActiveWindow.ActivePane.View.Zoom.Percentage = 75
    ActiveWindow.Next.Activate
    ActiveWindow.ActivePane.View.Zoom.Percentage = 75


    I'd be very appreciative if someone could explain to me what to do to fix the zoom macro, and what the problem is with the no-scrolling.


    Thanks very much.

    -- Eve

  2. #2
    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: Macros in Active Windows (Word 97)

    Can you post the macro code? I use Word 2000 now. While the interface is too different to think that the same issue would arise, I could skim the code for clues...

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

    Re: Macros in Active Windows (Word 97)

    As Jefferson wrote, unless you post the Tile Vertically macro, there is little we can say.

    About the Zoom problem: the error occurs if the active window is the last one in the Windows collection. In that case, ActiveWindow.Next is invalid. Try the following:

    ActiveWindow.ActivePane.View.Zoom.Percentage = 75
    On Error Resume Next
    ActiveWindow.Next.Activate
    If Err Then
    Windows(1).Activate
    End If
    On Error GoTo 0 ' or On Error GoTo ErrorHandler if you have an error handler
    ActiveWindow.ActivePane.View.Zoom.Percentage = 75

  4. #4
    New Lounger
    Join Date
    Nov 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros in Active Windows (Word 97)

    Hans, thank you, your version works perfectly. Thanks for the explanation too. I can see that it is applicable to some other problems that I've been struggling with. Will respond to Jefferson separately just to keep things neat.
    -- Eve

  5. #5
    New Lounger
    Join Date
    Nov 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros in Active Windows (Word 97)

    OK. I wasn't sure if I was allowed to post the code, as I don't have any way of getting the author's permission. I've got two copies of the same macro, attributed to two different authors, so I guess it isn't proprietary. But I have no way of locating either. Anyway, that's why I didn't post it before, but I'll put it up now. I'd like to know more about when it is and isn't OK to post macro code.

    Here it is.

    Dim lngWidth As Long, lngHeight As Long
    lngWidth = Application.Width * 0.5
    lngHeight = Application.Height
    If Windows(1).WindowState = wdWindowStateMaximize Then
    If Windows(2).WindowState = wdWindowStateMaximize Then
    Windows(1).WindowState = wdWindowStateNormal
    End If
    End If
    Windows(1).Width = lngWidth: Windows(1).Height = lngHeight
    Windows(1).Left = 0
    Windows(1).Top = 0
    Windows(2).Width = lngWidth: Windows(2).Height = lngHeight
    Windows(2).Left = lngWidth
    Windows(2).Top = 0


    -- Eve

  6. #6
    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: Macros in Active Windows (Word 97)

    I'm not sure I can give you a hard & fast rule on posting code, but it's great that you are conscientious about it and we'll just muddle through somehow.

    I was able to find a Word 97 PC and diagnose this. I'm guessing the macro was written for Word 2000, where you don't need to worry about the menu bar, toolbars, and status bar taking up space. For Word 97, the following should work better:

    <pre>Sub TileVerticalFull()
    ' In Word 97, fills the application's document area
    ' In Word 2000, fills the Windows desktop
    Dim lngWidth As Long, lngHeight As Long
    lngWidth = Application.UsableWidth * 0.5
    lngHeight = Application.UsableHeight
    If ActiveWindow.WindowState = wdWindowStateMaximize Then
    ActiveWindow.WindowState = wdWindowStateNormal
    End If
    With Windows(1)
    .Activate
    .Top = 0
    .Left = 0
    .Width = lngWidth
    .Height = lngHeight
    End With
    With Windows(2)
    .Activate
    .Top = 0
    .Left = lngWidth
    .Width = lngWidth
    .Height = lngHeight
    End With
    End Sub</pre>

    The only essential change is to use Application.UsableHeight and Application.UsableWidth instead of Application.Height and Application.Width, if I recall correctly.

  7. #7
    New Lounger
    Join Date
    Nov 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros in Active Windows (Word 97)

    Thank you so much, Jefferson, this is just great. What a difference! May I distribute it to a group of colleagues (writers, editors, and translators)? It would make a lot of people very happy. If that's OK, do you prefer to have your name on it or off it? On, I hope...

    -- Eve

  8. #8
    New Lounger
    Join Date
    Nov 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros in Active Windows (Word 97)

    Hi, Hans -- may I distribute your zoom macro to my writer's group? Many thanks again.

    -- Eve

  9. #9
    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: Macros in Active Windows (Word 97)

    Feel free, and no need to mention me, but you could link back to the top of this thread for people interested in learning more about the macro. Just add this comment:

    ' from Woody's Lounge
    ' http://www.wopr.com/cgi-bin/w3t/showflat.p...d&Number=195125

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

    Re: Macros in Active Windows (Word 97)

    Sure. You don't need to acknowledge me.

  11. #11
    New Lounger
    Join Date
    Nov 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros in Active Windows (Word 97)

    OK. Thanks very much to both. That's an excellent idea about referencing the top of the thread, and I'll do that. Many thanks!

    -- Eve

Posting Permissions

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