Class CustomView (Excel VBA)

The class CustomView represents a custom workbook view.

Item

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

Dim cvw as CustomView
Set cvw = ActiveWorkbook.CustomViews(ViewName:=1)

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

For Each

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

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

Delete

Deletes the object.

ActiveWorkbook.CustomViews(1).Delete

Name

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

Dim strName As String
strName = ActiveWorkbook.CustomViews(1).Name

PrintSettings

True if print settings are included in the custom view.

Dim booPrintSettings As Boolean
booPrintSettings = ActiveWorkbook.CustomViews(1).PrintSettings

RowColSettings

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

Dim booRowColSettings As Boolean
booRowColSettings = ActiveWorkbook.CustomViews(1).RowColSettings

Show

Displays the object.

ActiveWorkbook.CustomViews(1).Show

CustomViews.Add

Creates a new custom view.

Add (ViewName, PrintSettings, RowColSettings)

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

Arguments

The following argument is required

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

Optional arguments

The following arguments are optional

PrintSettings - True to include print settings in the custom view

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

PrintSettings - True to include print settings in the custom view

RowColSettings - 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.

Dim lngCount As Long
lngCount = ActiveWorkbook.CustomViews.Count

CustomViews.Item

Returns a single object from a collection.

Item (ViewName)

ViewName: The name or index number for the object.

Dim cvw As CustomView
Set cvw = ActiveWorkbook.CustomViews(ViewName:="Current Inventory")