none
Create a style based on selected paragraph style and base style RRS feed

  • Question

  • Hello,

    I would like to create a style that uses the style of the selected paragraph, but restore some paragraph settings using the BaseStyle which is the default paragraph style. The following code works when I run it as a macro, but when create a style from it, I noticed that it only works correctly for one paragraph style because when code creates the style, the based style is hard coded. in the newly created style. Is there any way to fix this? 

    Thanks for your help.

    Sub ClearStyle_AddStyle()
    Dim sGetStyleName As String
    Dim oGetBaseStyle As Variant
    Dim myStyle As Word.Style

    'Set myStyle = ActiveDocument.Styles.Add(Name:="UndoBlockQuote", _
    ' Type:=wdStyleTypeParagraph)

    'Get the paragraph style name
    sGetStyleName = Selection.Style.NameLocal
    oGetBaseStyle = ActiveDocument.Styles(sGetStyleName).BaseStyle

    'change the selected paragraph style to the base style

    With ActiveDocument.Styles(sGetStyleName)
             If .BaseStyle <> "" Then
                 '.Font = .BaseStyle.Font
                 .ParagraphFormat = .BaseStyle.ParagraphFormat
             End If
         End With
         Set myStyle = ActiveDocument.Styles.Add(Name:="UndoBQStyle", _
             Type:=wdStyleTypeParagraph)
     End Sub

    Monday, June 8, 2015 11:19 PM

Answers