View Single Post
 
Old 12-16-2022, 09:50 AM
Italophile Italophile is offline Windows 11 Office 2021
Expert
 
Join Date: Mar 2022
Posts: 539
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Either the style you are attempting to rename doesn't exist in the ActiveDocument, or you are trying to rename a built-in style, which isn't possible.

You need to add some error checking, for example:

Code:
Sub RenameCharacterStyles()
    Dim oldNames As Variant
    oldNames = Array("Old Style 1", "Old Style 2", "Old Style 3")

    Dim newNames As Variant
    newNames = Array("New Style 1", "New Style 2", "New Style 3")

    Dim i As Integer
    Dim sty As Style
    For i = 0 To UBound(oldNames)
        Set sty = ActiveDocument.Styles(oldNames(i))
        If Not sty Is Nothing Then
            If Not sty.BuiltIn Then sty.Name = newNames(i)
        End If
    Next i
End Sub
Reply With Quote