Solved

word vba - need to rename a set styles

Posted on 2007-04-05
2
938 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
Comment Utility
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
Comment Utility
Bullseye !
Great! Thanks!

- avi
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now