Solved

word vba - need to rename a set styles

Posted on 2007-04-05
2
1,001 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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