The Windows Collection and Window Objects

Of course, a Window object represents an Excel window. The Windows collection of the Application object is the collection of Window objects for all currently open windows in the currently running version of Excel. (Similarly, the Windows collection for a Workbook object contains only the windows in the workbook.)

The Arrange method of the Windows collection is used to arrange the current windows. The syntax is:

WindowsObject.Arrange(ArrangeStyle,

ActiveWorkbook, SyncHorizontal, SyncVertical)

The optional ArrangeStyle parameter can be one of the following XlArrangeStyle constants:

Enum XlArrangeStyle xlArrangeStyleVertical = -4166 xlArrangeStyleHorizontal = -4128

xlArrangeStyleTiled = 1 ' Default xlArrangeStyleCascade = 7 End Enum

We can set the ActiveWorkbook parameter to True to arrange only the visible windows of the active workbook. The default value is False, in which case all windows are arranged.

When ActiveWorkbook is True, the remaining parameters are evaluated (otherwise they are ignored). SyncHorizontal can be set to True to synchronize the horizontal scrolling windows of the active workbook. In other words, all windows scroll at the same time when one window is scrolled horizontally. The default value is False. Similarly, the SyncVertical parameter specifies vertical scrolling synchronization. Thus, the following code tiles the visible windows and enables horizontal scrolling synchronization:

ActiveWorkbook.Windows.Arrange

ArrangeStyle:=xlArrangeStyleTiled, SyncHorizontal:=True

To create a new window, we use the NewWindow method of the Workbook object, as in:

ThisWorkbook.NewWindow in which case a copy of the active window is created. This method also applies to an existing Window object and creates a copy of the window to which it is applied.

The Windows collection has a special property with respect to indexing, namely, the active window is always:

Windows(1)

The 58 members of the Window object are shown in Table 16-6.

Table 16-6. Members of the Window object

_DisplayRightToLeft<v9>

EnableResize

ScrollWorkbookTabs

Activate

FreezePanes

SelectedSheets

ActivateNext

GridlineColor

Selection

ActivatePrevious

GridlineColorlndex

SmallScroll

ActiveCell

Height

Split

ActiveChart

Index

SplitColumn

ActivePane

LargeScroll

SplitHorizontal

Active Sheet

Left

SplitRow

Application

NewWindow

SplitVertical

Caption

On Window

TabRatio

Close

Panes

Top

Creator

Parent

Type

DisplayFormulas

PointsToScreenPixelsX<v9>

UsableHeight

DisplayGridlines

PointsTo ScreenPixels Y<v9>

UsableWidth

DisplayHeadings

PrintOut

View

DisplayHorizontalScrollBar

PrintPreview

Visible

DisplayOutline

RangeFromPoint<v9>

VisibleRange

DisplayRightToLeft

RangeSelection

Width

DisplayVerticalScrollBar

ScrollColumn

WindowNumber

DisplayWorkbookTabs

ScrollIntoView<v9>

WindowState

DisplayZeros

ScrollRow

Zoom

0 0

Post a comment