• Different way to delete style aliases (Word 2000+)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Different way to delete style aliases (Word 2000+)

    Author
    Topic
    #404845

    I know Andrew Lockton has already posted a macro for this (post 338863), but FWIW I was tinkering on some code to clear out “char, char” styles and came up with this alternate method:

    Sub RemoveStyleAliases()
    Dim sty As Style
    For Each sty In ActiveDocument.Styles
        sty.NameLocal = Split(sty.NameLocal, ",")(0)
    Next sty
    End Sub
    

    This also shows how to coax a single item out of a function that returns an array without using an intermediate assignment. It’s not well documented, and it can save a few lines of code.

    Enjoy! munch

    Viewing 3 reply threads
    Author
    Replies
    • #826816

      That method is a whole lot more succinct and perfect for the purpose of removing the char char aliases – well done.

      My original macro was designed for another purpose and had to work in Word 97 where the split function wasn’t available. I once had to recreate the split function for an Office 97 job so perhaps I should have considered doing it that way in the first place.

    • #826817

      That method is a whole lot more succinct and perfect for the purpose of removing the char char aliases – well done.

      My original macro was designed for another purpose and had to work in Word 97 where the split function wasn’t available. I once had to recreate the split function for an Office 97 job so perhaps I should have considered doing it that way in the first place.

    • #914920

      Andrew,
      your macro also works for all the other aliases that creep into documents. Great idea.
      I did find one problem however. It caused all the built-in styles to appear in the Styles-in-Use list.
      I added an if statement (If sty.InUse = True Then) and now it doesn’t add those extra styles

      Here is my modified version of your macro:

      Sub RemoveStyleAliasesRevised()
      ‘ Reduce each style to its first alias.
      ‘ This will generally be the name of the built-in style.
      ‘ Modified JMcC to limit styles to those with .inUse flag set

      Dim sty As Style

      For Each sty In ActiveDocument.Styles
      If sty.InUse = True Then
      Debug.Print “Removing ” & sty & ” aliases”
      sty.NameLocal = Split(sty.NameLocal, “,”)(0)
      End If
      Next sty
      End Sub

    • #914921

      Andrew,
      your macro also works for all the other aliases that creep into documents. Great idea.
      I did find one problem however. It caused all the built-in styles to appear in the Styles-in-Use list.
      I added an if statement (If sty.InUse = True Then) and now it doesn’t add those extra styles

      Here is my modified version of your macro:

      Sub RemoveStyleAliasesRevised()
      ‘ Reduce each style to its first alias.
      ‘ This will generally be the name of the built-in style.
      ‘ Modified JMcC to limit styles to those with .inUse flag set

      Dim sty As Style

      For Each sty In ActiveDocument.Styles
      If sty.InUse = True Then
      Debug.Print “Removing ” & sty & ” aliases”
      sty.NameLocal = Split(sty.NameLocal, “,”)(0)
      End If
      Next sty
      End Sub

    Viewing 3 reply threads
    Reply To: Reply #914920 in Different way to delete style aliases (Word 2000+)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel