Name

workbook.Windows [= setting]

Synopsis

Returns the collection of Excel windows in which the workbook is displayed. Use the NewWindow method to open new windows, the Window Close method to close existing windows, and the Windows Arrange method to arrange open windows. If you close the last window displaying a workbook, Excel prompts the user to save any changes before closing.

The following code opens two new windows for the current workbook, arranges them, then closes the three new windows:

ThisWorkbook.NewWindow
ThisWorkbook.NewWindow
ThisWorkbook.Windows.Arrange
If MsgBox("Click OK to close new windows.", vbOKCancel) Then
    ThisWorkbook.Windows(3).Close
    ThisWorkbook.Windows(2).Close
End If
ThisWorkbook.Windows.Arrange

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.