Various Windows in Excel example

Various Windows in Excel example

Windows

Refers to Excel physical structure object which ensures window level customization. Like, Zooming window, Minimize, Maximize etc. In this article we will see what all Window level customization excel offers.

New Window

Opening multiple windows into a workbook provides an easy way to view or work with different areas of your workbook simultaneously. Any changes made in any of the windows are made to the workbook.

You can save multiple windows into a workbook by saving it while multiple windows are open. To remove windows that have been saved with your workbook, close all multiple windows, and then save your document.

Open multiple windows

  1. Start Microsoft Excel and open any workbook.
  2. In Microsoft Office Excel 2007, click the View tab, and then click New Window in the Window group.In Microsoft Office Excel 2003 and in earlier versions of Excel, click New Window on the Window menu.

Arrange All

  1. Under View ribbon locate Window group
  2. Click Arrange All button
  3. A popup will appear asking followings:
    • Tiled: all windows will be shown tiled (refer figure 1.0)
    • Horizontal: all open windows will be shown horizontally (refer figure 1.1)
    • Vertical: all open windows will be shown vertically (refer figure 1.2)
    • Cascade: all open windows will be shown in cascade manner (refer figure 1.2)
    • Windows of active workbook: shows all workbooks as windows if checks to true
  4. Click OK

Tiled:

figure 1.0

Horizontal:

figure 1.1

Vertical:

figure 1.2

Cascade:

figure 1.3

Lets code to automate various windows in Excel. The given examples are created using VSTO (Visual Studio Tool for Office) hence following prerequisites are recommended:

  1. Visual Studio 2015 or above having Microsoft Office for Developer Tool installed
  2. Create Excel Addin in C# or VB code style (Visual Studio Tools for Office)
  3. Excel 2010 or above
  4. Create a ribbon designer and put button

C# code example

private void btnArrangeAll_Click(object sender, RibbonControlEventArgs e)
{
	//Get active window reference
	excel.Window oWindow = Globals.ThisAddIn.Application.ActiveWindow;

	//Create new window
	oWindow.NewWindow();

	//get workbook reference
	excel.Workbook oWorkbook = Globals.ThisAddIn.Application.ActiveWorkbook;


	//Arrange tiled
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleTiled);

	//Arrange horizontal
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleHorizontal);

	//Arrange vertical
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleVertical);

	//Arrange Cascade
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleCascade);
}

VB.Net code example

Private Sub ArrangeAll_Click(sender As Object, e As RibbonControlEventArgs) Handles ArrangeAll.Click
	'Get active window reference
	Dim oWindow As excel.Window
	oWindow = Globals.ThisAddIn.Application.ActiveWindow

	'Create New window
	oWindow.NewWindow()

	'get workbook reference
	Dim oWorkbook As excel.Workbook
	oWorkbook = Globals.ThisAddIn.Application.ActiveWorkbook

	'Arrange tiled
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleTiled)

	'Arrange horizontal
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleHorizontal)

	'Arrange vertical
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleVertical)

	'Arrange Cascade
	oWorkbook.Windows.Arrange(excel.XlArrangeStyle.xlArrangeStyleCascade)
End Sub

VBA code example

Private Sub ArrangeAllWindows()
    'Get active window reference
    Dim oWindow As Window
    Set oWindow = ActiveWindow

    'Create New window
    oWindow.NewWindow

    'get workbook reference
    Dim oWorkbook As Workbook
    Set oWorkbook = ActiveWorkbook

    'Arrange tiled
    oWorkbook.Windows.Arrange xlArrangeStyleTiled

    'Arrange horizontal
    oWorkbook.Windows.Arrange xlArrangeStyleHorizontal

    'Arrange vertical
    oWorkbook.Windows.Arrange xlArrangeStyleVertical

    'Arrange Cascade
    oWorkbook.Windows.Arrange xlArrangeStyleCascade
End Sub

Next >> How to hide, split, unhide workbook in Excel

Leave a Reply

Your email address will not be published. Required fields are marked *