Class TableStyle (Excel VBA)

The class TableStyle represents a single style that can be applied to a table or slicer.

The main procedures of class TableStyle are Delete and TableStyles.Add

Set

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

Dim tblsty as TableStyle
Set tblsty = ActiveWorkbook.DefaultPivotTableStyle

The following procedures can be used to set variables of type TableStyle: ListObject.TableStyle, Duplicate, TableStyles.Item, TableStyles.Add, Workbook.DefaultPivotTableStyle, Workbook.DefaultTableStyle, Workbook.DefaultSlicerStyle and Workbook.TableStyles

For Each

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

Dim tblstyDefaultSlicerStyle As TableStyle
For Each tblstyDefaultSlicerStyle In Application.DefaultSlicerStyle
	
Next tblstyDefaultSlicerStyle

Methods

These are the main methods of the TableStyle class

Delete - Deletes the TableStyle object.

ActiveWorkbook.DefaultPivotTableStyle.Delete

TableStyles.Add - Creates a new TableStyle object and adds it to the collection.

Dim strTableStyleName As String: strTableStyleName = 
Dim tblsty As TableStyle
Set tblsty = ActiveWorkbook.TableStyles.Add(TableStyleName:=strTableStyleName)

Other Methods

Duplicate - Duplicates the TableStyle object and returns a reference to the new copy.

TableStyles.Item - Returns a single TableStyle object from the collection.

Properties

BuiltIn true if the style is a built-in style.

Name returns the name of the object.

NameLocal returns or sets the name of the object in the language of the user.

Parent returns the parent object for the specified object. Read-only.

ShowAsAvailablePivotTableStyle sets or returns whether a style is shown in the gallery for PivotTable styles.

ShowAsAvailableSlicerStyle returns or sets whether the specified table style is shown as available in the slicer styles gallery.

ShowAsAvailableTableStyle returns or sets a table style shown as available in the table styles gallery.

ShowAsAvailableTimelineStyle returns or sets whether the specified table style is shown as available in the timeline styles gallery.

TableStyleElements returns the TableStyleElements object.

TableStyles.Count returns the number of objects in the collection.

TableStyles.Parent returns the parent object for the specified object. Read-only.