Solved

word vba - need to rename a set styles

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to mongodb 2 46
How to produce a SHA-1 hash function in vb6 in order to save it to a table 8 36
How to open a ZIP file. 6 39
How to Add / Edit Windows Menu 4 49
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …

930 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

17 Experts available now in Live!

Get 1:1 Help Now