Solved

word vba - need to rename a set styles

Posted on 2007-04-05
2
985 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

829 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