Workbook Views in Excel with example

Workbook Views in Excel with example

Views

Excel offers various views mentioned in detail below:

  1. Normal: default view (refer figure 1.0)
  2. Page Break: this view helps when user is intended to print the job. Turning Page Break view let the user decide which area will go under or outside page while printing. (refer figure 1.1)
  3. Page Layout: offers print preview over the data. (refer figure 1.2)
  4. Custom Views: to save specific display settings (such as hidden rows and columns, cell selections, filter settings, and window settings) and print settings (such as page settings, margins, headers and footers, and sheet settings etc.) for a worksheet so that you can quickly apply these settings to that worksheet when needed. You can also include a specific print area in a custom view.

Normal View

Navigate View ribbon and choose Normal from Workbook Views group:

figure 1.0

Page Break View

Navigate View ribbon and choose Page Break from Workbook Views group:

figure 1.1

Page Layout

Navigate View ribbon and choose Page Layout from Workbook Views group:

figure 1.2

Custom Views

  • On a worksheet, change the display and print settings that you want to save in a custom view.
  • Go to View > Workbook Views > Custom Views > Add.
  • In the Name box, type a name for the view.
  • Under Include in view, select the check boxes of the settings that you want to include. All the views that you add to the workbook appear under Views in the Custom Views dialog box. When you select a view in the list, and then click Show, the worksheet that was active when you created the view will be displayed.
figure 1.3

Note: If any worksheet in the workbook contains an Excel table, then Custom Views will not be available anywhere in the workbook.

C# code example

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

	//Normal view
	oWindow.View = excel.XlWindowView.xlNormalView;

	//Page break view
	oWindow.View = excel.XlWindowView.xlPageBreakPreview;

	//Layout view
	oWindow.View = excel.XlWindowView.xlPageLayoutView;

	
	//reference active workbook
	excel.Workbook oWorkbook = Globals.ThisAddIn.Application.ActiveWorkbook;
	
	//Add custom view
	oWorkbook.CustomViews.Add("myNewView", true, true);

	//Show view
	oWorkbook.CustomViews["myNewView"].Show();
}

VB.Net code example

Private Sub btnViewsExample_Click(sender As Object, e As RibbonControlEventArgs) Handles btnViewsExample.Click
	'Get window reference
	dim oWindow As excel.Window
	oWindow = Globals.ThisAddIn.Application.ActiveWindow

	'Normal view
	oWindow.View = excel.XlWindowView.xlNormalView

	'Page break view
	oWindow.View = excel.XlWindowView.xlPageBreakPreview

	'Layout view
	oWindow.View = excel.XlWindowView.xlPageLayoutView

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

	'Add custom view
	oWorkbook.CustomViews.Add("myNewView", true, true)

	'Show view
	oWorkbook.CustomViews("myNewView").Show()
End Sub

VBA code example

Public Sub ManipulateViews()
    'Get window reference
    Dim oWindow As Window
    Set oWindow = ActiveWindow

    'Normal view
    oWindow.View = xlNormalView

    'Page break view
    oWindow.View = xlPageBreakPreview

    'Layout view
    oWindow.View = xlPageLayoutView

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

    'Add custom view
    oWorkbook.CustomViews.Add "myNewView", True, True

    'Show view
    oWorkbook.CustomViews("myNewView").Show
End Sub

Next >> Understand windows in Excel

Leave a Reply

Your email address will not be published.