Class Window (Word VBA)

The class Window represents a window. Many document characteristics, such as scroll bars and rulers, are actually properties of the window.

The main procedures of class Window are Activate, Close and Windows.Add

Set

To use a Window class variable it first needs to be instantiated, for example

Dim wnd as Window
Set wnd = ActiveWindow

The following procedures can be used to set variables of type Window: Application.ActiveWindow, Application.NewWindow, Document.ActiveWindow, NewWindow, Next, Previous, Windows.Add, Windows.Item, Application.Windows and Document.Windows

For Each

Here is an example of processing the Window items in a collection.

Dim win As Window 
For Each win In Windows 
 win.DisplayVerticalScrollBar = True 
 win.DisplayHorizontalScrollBar = True 
Next win

Themes

The following procedures in this class have been grouped together and are described on a separate theme page

Display/Show with its procedures DisplayHorizontalScrollBar, DisplayLeftScrollBar, DisplayRightRuler, DisplayRulers, DisplayScreenTips, DisplayVerticalRuler, DisplayVerticalScrollBar and ShowSourceDocuments

Methods

These are the main methods of the Window class

Activate - Activates the specified window.

ActiveWindow.Activate

Close - Closes the specified window.

ActiveWindow.Close

Windows.Add - Returns a Window object that represents a new window of a document.

Dim wnd As Window
Set wnd = Windows.Add()

Other Methods

GetPoint - Returns the screen coordinates of the specified range or shape.

Dim lngScreenPixelsLeft As Long: lngScreenPixelsLeft = 
Dim lngScreenPixelsTop As Long: lngScreenPixelsTop = 
Dim lngScreenPixelsWidth As Long: lngScreenPixelsWidth = 
Dim lngScreenPixelsHeight As Long: lngScreenPixelsHeight =  
ActiveWindow.GetPoint ScreenPixelsLeft:=lngScreenPixelsLeft, ScreenPixelsTop:=lngScreenPixelsTop, ScreenPixelsWidth:=lngScreenPixelsWidth, ScreenPixelsHeight:=lngScreenPixelsHeight, obj:=

LargeScroll - Scrolls a window or pane by the specified number of screens.

ActiveWindow.LargeScroll

PageScroll - Scrolls through the specified pane or window page by page.

ActiveWindow.PageScroll

PrintOut - Prints all or part of the document displayed in the specified window.

ActiveWindow.PrintOut

RangeFromPoint - Returns the Range or Shape range that is located at the point specified by the screen position coordinate pair.

Dim lngx As Long: lngx = 
Dim lngy As Long: lngy =  
Dim rngRangeFromPoint As Range
Set rngRangeFromPoint = ActiveWindow.RangeFromPoint(x:=lngx, y:=lngy)

ScrollIntoView - Scrolls through the document window so the specified range or shape is displayed in the document window.

ActiveWindow.ScrollIntoView obj:=

SmallScroll - Scrolls a window or pane by the specified number of lines.

ActiveWindow.SmallScroll

Windows.Arrange - Arranges all open document windows in the application workspace.

Windows.Arrange

Properties

Active true if the specified window is active.

Dim booActive As Boolean
booActive = ActiveWindow.Active

ActivePane returns a Pane object that represents the active pane for the specified window.

Dim panActivePane As Pane
Set panActivePane = ActiveWindow.ActivePane

Caption returns or sets the caption text for the window that is displayed in the title bar of the document or application window.

ActiveWindow.Caption =

Document returns a Document object associated with the specified pane, window, or selection.

Dim docDocument As Document
Set docDocument = ActiveWindow.Document

DocumentMap true if the document map is visible.

ActiveWindow.DocumentMap = True

EnvelopeVisible true if the email message header is visible in the document window. The default value is False.

ActiveWindow.EnvelopeVisible = True

Height returns or sets the height of the window (in points).

ActiveWindow.Height =

HorizontalPercentScrolled returns or sets the horizontal scroll position as a percentage of the document width.

ActiveWindow.HorizontalPercentScrolled =

Hwnd returns a Long that indicates the window handle of the specified window.

Dim lngHwnd As Long
lngHwnd = ActiveWindow.Hwnd

IMEMode returns or sets the default start-up mode for the Japanese Input Method Editor (IME).

ActiveWindow.IMEMode = wdIMEModeAlpha

Index returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = ActiveWindow.Index

Left returns or sets a Long that represents the horizontal position of the specified window, measured in points.

ActiveWindow.Left =

Next returns the next document window in the collection of open document windows.

Dim wndNext As Window
Set wndNext = ActiveWindow.Next

Panes returns a Panes collection that represents all the window panes for the specified window.

Dim pnsPanes As Panes
Set pnsPanes = ActiveWindow.Panes

Parent returns an object that represents the parent object of the specified Window object.

Dim objParent As Object
Set objParent = ActiveWindow.Parent

Previous returns the previous document window in the collection open document windows.

Dim wndPrevious As Window
Set wndPrevious = ActiveWindow.Previous

Selection returns the Selection object that represents a selected range or the insertion point.

Dim slcSelection As Selection
Set slcSelection = ActiveWindow.Selection

Split true if the window is split into multiple panes.

ActiveWindow.Split = True

SplitVertical returns or sets the vertical split percentage for the specified window.

ActiveWindow.SplitVertical =

StyleAreaWidth returns or sets the width of the style area in points.

ActiveWindow.StyleAreaWidth =

Thumbnails sets or returns a Boolean that represents whether thumbnail images of the pages in a document are displayed along the left side of the Microsoft Word document window.

ActiveWindow.Thumbnails = True

Top returns or sets the vertical position of the specified document window, in points.

ActiveWindow.Top =

Type returns the window type.

Dim wwtType As WdWindowType
wwtType = ActiveWindow.Type

UsableHeight returns the height (in points) of the active working area in the specified document window. Read-only Long.

Dim lngUsableHeight As Long
lngUsableHeight = ActiveWindow.UsableHeight

UsableWidth returns the width (in points) of the active working area in the specified document window.

Dim lngUsableWidth As Long
lngUsableWidth = ActiveWindow.UsableWidth

VerticalPercentScrolled returns or sets the vertical scroll position as a percentage of the document length.

ActiveWindow.VerticalPercentScrolled =

View returns a View object that represents the view for the specified window or pane.

Dim vwView As View
Set vwView = ActiveWindow.View

Visible true if the specified object is visible.

ActiveWindow.Visible = True

Width returns or sets the width of the specified document window, in points.

ActiveWindow.Width =

WindowNumber

Dim lngWindowNumber As Long
lngWindowNumber = ActiveWindow.WindowNumber

WindowState returns or sets the state of the specified document window or task window.

ActiveWindow.WindowState = wdWindowStateMaximize

Windows.Count returns a Long that represents the number of windows in the collection.

Dim lngCount As Long
lngCount = Windows.Count

Windows.Parent returns an object that represents the parent object of the specified Windows object.

Dim objParent As Object
Set objParent = Windows.Parent

SyncScrollingSideBySide

Windows.SyncScrollingSideBySide = True