Applies To
Styles Collection.
Description
Creates a new style and adds it to the list of styles available for the current workbook. Returns a Style object.
Syntax
object.Add(name, basedOn)
object
Required. The Styles object.
name
Required. A string specifying the name for the new style.
basedOn
Optional. A reference to a cell that will be used as the basis for the new style. If specified, the newly created style will be given a style based on that cell. If omitted, the newly created style will be based on the Normal style.
Remarks
If a style with the specified name already exists, this method redefines the style based on the cell specified in basedOn. The following example redefines the Normal style based on the active cell:
ActiveWorkbook.Styles.Add name:="Normal", _ basedOn:=ActiveCell
Example
This example defines a new style based on cell A1 on Sheet1.
Worksheets("Sheet1").Activate ActiveWorkbook.Styles.Add name:="myNewStyle", _ basedOn:=ActiveSheet.Range("A1")
This example defines a new style that includes only the Font property.
With ActiveWorkbook.Styles.Add(name:="theNewStyle") .IncludeNumber = False .IncludeFont = True .IncludeAlignment = False .IncludeBorder = False .IncludePatterns = False .IncludeProtection = False .Font.Name = "Arial" .Font.Size = 18 End With