Class CustomView (Excel VBA)

The class CustomView represents a custom workbook view.

Set

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

Dim strViewName As String: strViewName = 
Dim wb As Workbook: Set wb = 
Dim cvw As CustomView
Set cvw = wb.CustomViews.Add(ViewName:=strViewName)

The following procedures can be used to set variables of type CustomView: CustomViews.Item, CustomViews.Add and Workbook.CustomViews

For Each

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

Dim wb As Workbook: Set wb = 
Dim cvwCustomView As CustomView
For Each cvwCustomView In wb.CustomViews
	
Next cvwCustomView

Delete

Deletes the object.

Name

Returns a String value that represents the name of the object.

Parent

Returns the parent object for the specified object. Read-only.

PrintSettings

True if print settings are included in the custom view.

With Worksheets(1) 
 .Cells(1,1).Value = "Name" 
 .Cells(1,2).Value = "Print Settings" 
 .Cells(1,3).Value = "RowColSettings" 
 rw = 0 
 For Each v In ActiveWorkbook.CustomViews 
 rw = rw + 1 
 .Cells(rw, 1).Value = v.Name 
 .Cells(rw, 2).Value = v.PrintSettings 
 .Cells(rw, 3).Value = v.RowColSettings 
 Next 
End With

RowColSettings

True if the custom view includes settings for hidden rows and columns (including filter information).

With Worksheets(1) 
 .Cells(1,1).Value = "Name" 
 .Cells(1,2).Value = "Print Settings" 
 .Cells(1,3).Value = "RowColSettings" 
 rw = 0 
 For Each v In ActiveWorkbook.CustomViews 
 rw = rw + 1 
 .Cells(rw, 1).Value = v.Name 
 .Cells(rw, 2).Value = v.PrintSettings 
 .Cells(rw, 3).Value = v.RowColSettings 
 Next 
End With

Show

Displays the object.

CustomViews.Add

Creates a new custom view.

Syntax : expression.Add (ViewName, PrintSettings, RowColSettings)

ActiveWorkbook.CustomViews.Add "Summary", True, True

Arguments

The following argument is required

ViewName (String) - The name of the new view.

The following arguments are optional

PrintSettings (Boolean) - True to include print settings in the custom view.

RowColSettings (Boolean) - True to include settings for hidden rows and columns (including filter information) in the custom view.

CustomViews.Count

Returns a Long value that represents the number of objects in the collection.

CustomViews.Item

Returns a single object from a collection.

Syntax : expression.Item (ViewName)

ViewName: The name or index number for the object.

ThisWorkbook.CustomViews.Item("Current Inventory") _ 
 .PrintSettings = True

CustomViews.Parent

Returns the parent object for the specified object. Read-only.