[UPDATE]Arrange Windows Side-by-side

J

J.E. McGimpsey

Here's an update to the macro I posted earlier to arrange windows
side-by-side, rather than top-to-bottom. As before, put it in a
global template.

The original had one major problem that I've seen - it would throw a
run-time error if all windows were minimized (on the dock).

To fix that I added the "If cVisibleWindows.Count <> 0 Then" code.

Unfortunately, at least on my machine, this had one side-effect
(bug?). If the macro ended due to all windows being docked, the
cursor stayed as a watch, which might tend to make the user think
the macro hung. So I added a line to reset the cursor.

Please let me know if you see any other problems or have suggestions
for improvement.

Public Sub WindowArrangeAll()
'J.E. McGimpsey
'Rev. 1 (JEM, 20030908): added line to prevent error if
' all windows minimized.
Const BOTTOMSPACE As Integer = 25
Const RIGHTSPACE As Integer = 50
Dim cVisibleWindows As New Collection
Dim oWindow As Window
Dim i As Integer
Dim iWidth As Integer
Dim iHeight As Integer

For Each oWindow In Windows
If oWindow.WindowState <> wdWindowStateMinimize Then _
cVisibleWindows.Add oWindow
Next oWindow
Debug.Print cVisibleWindows.Count
With cVisibleWindows
If .Count <> 0 Then
iWidth = (Application.UsableWidth - RIGHTSPACE) / .Count
iHeight = Application.UsableHeight - BOTTOMSPACE
For i = 1 To .Count
With .Item(i)
.Activate
.WindowState = wdWindowStateNormal
.Width = iWidth
.Left = (i - 1) * iWidth - (i > 1)
.Top = 0
.Height = iHeight
End With
Next i
Else
System.Cursor = wdCursorNormal
End If
End With
End Sub
 

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