Solved

word vba - need to rename a set styles

Posted on 2007-04-05
2
994 Views
Last Modified: 2012-08-13
Hi all,

I have a set of custom Word styles that all start with a certain prefix, in my case "_CO ".
I now want to change the prefix to something else.
Can some kind VBA whiz pls show me how I can use VBA to write a loop that will rename all these styles starting with "_CO ", as above.

This is sort of urgent.

tia

- avi
0
Comment
Question by:progtw
2 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 18858996
Hi avi,

Sure, give this a try, just change the old/new prefix variables and it should do the trick for you:

Sub RenameStyles()
 Dim STY As Style, OldPrefix As String, NewPrefix As String
 OldPrefix = "_CO"
 NewPrefix = "_OC"
 For Each STY In ActiveDocument.Styles
  If Not STY.BuiltIn Then
   If Left(STY.NameLocal, Len(OldPrefix)) = OldPrefix Then
    STY.NameLocal = NewPrefix & Mid(STY.NameLocal, Len(OldPrefix) + 1)
   End If
  End If
 Next
End Sub

Matt
0
 

Author Comment

by:progtw
ID: 18870313
Bullseye !
Great! Thanks!

- avi
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question