View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default How to use CompareSideBySide method?

Ed,
I don't have XL2003, so I can't say about CompareSideBySide. However, I use
this from a menu item to resize all windows based on the the size of the
active window.
Amend to your needs.

Private Type Rect
rLeft As Single
rTop As Single
rWidth As Single
rHeight As Single
End Type

Public Function CustomArrangeWindows()
Dim Wnd As Window
Dim NonActRect As Rect

Const MINIMUM_HEIGHT As Long = 30
Const MINIMUM_WIDTH As Long = 50

If ActiveWindow.WindowState < xlNormal Then
MsgBox "Cannot perform custom arrangement when the active window is
minimised or maximised."
Exit Function
End If

With NonActRect
If ResizeActiveWindow() = True Then
'Arrange horizontally, below the ActiveWindow
.rLeft = 0

.rTop = ActiveWindow.Height

.rWidth = Application.UsableWidth
'To avoid error trying to set the window too small
If .rWidth < MINIMUM_WIDTH Then .rWidth = MINIMUM_WIDTH

.rHeight = Application.UsableHeight - .rTop
'To avoid error trying to set the window too small
If .rHeight < MINIMUM_HEIGHT Then .rHeight = MINIMUM_HEIGHT
Else
'Arrange vetically, to the right of the ActiveWindow
.rLeft = ActiveWindow.Width

.rTop = 0

.rWidth = Application.UsableWidth - .rLeft
'To avoid error trying to set the window too small
If .rWidth < MINIMUM_WIDTH Then .rWidth = MINIMUM_WIDTH

.rHeight = Application.UsableHeight
'To avoid error trying to set the window too small
If .rHeight < MINIMUM_HEIGHT Then .rHeight = MINIMUM_HEIGHT
End If

For Each Wnd In Windows
If (Wnd.Caption < ActiveWindow.Caption) And (Wnd.Visible = True)
Then
Wnd.Left = .rLeft
Wnd.Top = .rTop
Wnd.Width = .rWidth
Wnd.Height = .rHeight
End If
Next
End With

End Function

'Helper routine for CustomArrangeWindows
Private Function ResizeActiveWindow() As Boolean
Dim StretchWidth As Boolean

With ActiveWindow
.Left = 0
.Top = 0
'see if we should stretch the .Width or the .Height
If .Width .Height Then
StretchWidth = True
.Width = Application.UsableWidth
Else
StretchWidth = False
.Height = Application.UsableHeight
End If
End With

ResizeActiveWindow = StretchWidth

End Function

NickHK

"Ed" wrote in message
oups.com...
I've got XL2003. I noticed the "CompareSideBySide" in the Window
menu, and thought I would explore that in VBA. I use two monitors and
spread the Excel application across both, with two workbooks open, one
i each monitor. I was hoping a simple macro could resize everything
and place the two workbooks, rather than having to resize everything
manually.

But I can't find much on the CompareSideBySide method. Everything
I've seen specifies only one workbook name. My Personal.xls always
opens with any other workbook because I have macros. I wonder if I
can specify the windows to resize and compare so Excel doesn't grab
the Personal window just because it's open.

If anyone has any insight or examples on using this, I would
appreciate the info. Thank you.
Ed