Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Different way to delete style aliases (Word 2000+)

    I know Andrew Lockton has already posted a macro for this (<post#=338863>post 338863</post#>), but FWIW I was tinkering on some code to clear out "char, char" styles and came up with this alternate method:
    <pre>Sub RemoveStyleAliases()
    Dim sty As Style
    For Each sty In ActiveDocument.Styles
    sty.NameLocal = Split(sty.NameLocal, ",")(0)
    Next sty
    End Sub
    </pre>

    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! <img src=/S/munch.gif border=0 alt=munch width=19 height=17>

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Different way to delete style aliases (Word 2000+)

    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.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Different way to delete style aliases (Word 2000+)

    Here's the VB6 string functions written in VB5 if you're interested. These are much better than the ones in the knowledgebase.

    http://www.freevbcode.com/ShowCode.asp?ID=17

  4. #4
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Cherrybrook, New South Wales, Australia
    Posts
    116
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Different way to delete style aliases (Word 2000+)

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •