How can I tile documents vertically in Word 2000?

Article contributed by Jay Freedman

In Word 2000, each document lives in a separate window. This means that you can place them side by side with the Tile Vertically command from the Task Bar's right-click menu. But-there's always a gotcha – if all other program windows aren't minimized, they'll be squeezed in among the Word documents. Of course there's a better way! It involves using a macro; so if you're  not familiar with using macros, see What do I do with macros sent to me by other users to help me out?

This macro starts by listing in an array all the open and non-minimized Word documents. When the list is complete, the macro knows how many there are. Next it grabs one of the windows and maximizes it, to get the width and height measurements of the full screen. (Through an API call, Windows can easily tell you these sizes in pixels, but Word wants to size its windows in points.) Our goal is to set each document window to a fraction of the total width that depends on how many documents are in the list. If there are two documents, each gets half of the full screen width; if there are three documents, each gets a third, and so on.

Next, the macro runs through the list of windows, setting each to the same size. Each window is positioned (by setting its .Left property to a multiple of the desired window width) just to the right of the one before it.

Finally, the macro activates the window that had the focus when the macro started. Unlike the Task Bar's Tile Vertically command, this window hasn't been forced to the leftmost position; all windows appear in the same order as they are listed on Word's Window menu.

Public Sub WindowTileVertical()

Dim oWind As Window ' working object
Dim nActiveWindowIndex As Long ' save to reactivate at end

Dim nNonMinWindows() As Long ' list of nonminimized windows
Dim nNonMinWindowsCount As Long ' length of the list

Dim nScreenWidth As Long ' width & height of full
Dim nScreenHeight As Long ' screen in points

Dim nDesiredWidth As Long ' width each window should be
Dim nIndex As Long ' For loop index

' Save active window's index
nActiveWindowIndex = ActiveWindow.Index

' Find out how many Word windows are not minimized 
' (i.e., maximized or normal), and store them in the
' nNonMinWindows array
nNonMinWindowsCount = 0
For Each oWind In Windows
    If oWind.WindowState <> wdWindowStateMinimize Then
        nNonMinWindowsCount = nNonMinWindowsCount + 1
        ReDim Preserve nNonMinWindows(nNonMinWindowsCount - 1)
        nNonMinWindows(nNonMinWindowsCount - 1) = oWind.Index
    End If
Next oWind

If nNonMinWindowsCount < 1 Then Exit Sub

' Maximize the current window,  to get the
' screen width and height in points
With ActiveWindow
    .WindowState = wdWindowStateMaximize
    nScreenWidth = .Width
    nScreenHeight = .Height
End With

' The desired width is the screen width
' divided by the number of windows being tiled
nDesiredWidth = nScreenWidth / nNonMinWindowsCount

' Set each window to the desired size. Offset each one
' horizontally to sit to the right of the one before.

For nIndex = 0 To nNonMinWindowsCount - 1
    Set oWind = Windows(nNonMinWindows(nIndex))

    With oWind
        .Activate
        .WindowState = wdWindowStateNormal

        .Width = nDesiredWidth
        .Height = nScreenHeight

        .Top = 0
        .Left = nIndex * nDesiredWidth
    End With

Next nIndex

Set oWind = Nothing
Windows(nActiveWindowIndex).Activate

End Sub