Creating Styles


Styles.Add Method

Use the Add method to create a new user-defined style and add it to the Styles collection.

ActiveDocument.Styles.Add Name:="New Style 1", _ 
                          Type:=wdStyleType.wdStyleTypeParagraph


Paragragh Styles

This example creates a new paragraph style called "New Paragraph Style 1"

Dim objStyle As Style 
Set objStyle = ActiveDocument.Styles.Add(Name:="New Paragraph Style 1", _
                                         Type:=wdStyleType.wdStylesParagraph)

With objStyle
   .Font.Bold
   .Font.Italic
   .Font.Name
   .Font.Size = 14
End With


Character Styles

This example creates a new character style called "New Character Style 1"

Dim objStyle As Style 
Set objStyle = ActiveDocument.Styles.Add(Name:="New Character Style 1", _
                                         Type:=wdStyleType.wdStyleTypeCharacter)



Styles based on existing styles

A style can be based on another style

Dim objStyle As Style 
Set objStyle = ActiveDocument.Styles.Add Name:="newstyle", _
                                         Type:=wdStyleType.wdStyleTypeParagraph
objStyle.BaseStyle = "Chapter"


A Style object includes the following attributes:

ActiveDocument.Styles("Normal").AutomaticallyUpdate = False 
ActiveDocument.Styles("Normal").BaseStyle = ""
ActiveDocument.Styles("Normal").NextParagraphStyle = "Normal"
ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle = False
  • Font

ActiveDocument.Styles("Normal").Font.Name = "Arial" 
ActiveDocument.Styles("Normal").Font.Size = 12
ActiveDocument.Styles("Normal").Font.Bold = False
ActiveDocument.Styles("Normal").Font.Italic = False
ActiveDocument.Styles("Normal").Font.Underline = False
ActiveDocument.Styles("Normal").Font.TextColor.RGB = RGB(200, 200, 200)
  • Paragraph

If (objStyle.Type = wdStyleType.wdStyleTypeParagraph) Then 
   objStyle.ParagraphFormat.Alignment = wdParagraphAlignment.wdAlignParagraphLeft
End If
  • Tabs

ActiveDocument.Styles("Normal").ParagraphFormat.TabStops 
  • Borders

ActiveDocument.Styles("Normal").Borders 
  • Language

ActiveDocument.Styles("Normal").LanguageID 
  • Frame

ActiveDocument.Styles("Normal").Frame 
  • Numbering

ActiveDocument.Styles("Normal").LinkToListTemplate _
      
                                ListTemplate:= ListGalleries(wdListGalleryType.wdBulletGallery).ListTemplates(1), _
                                ListLevelNumber:=1
  • Shortcut Keys



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext