![]() |
#1
|
|||
|
|||
![]() Code:
Sub RenameCharacterStyles() Dim oldNames As Variant oldNames = Array("Old Style 1", "Old Style 2", "Old Style 3") Dim newNames As Variant newNames = Array("New Style 1", "New Style 2", "New Style 3") Dim i As Integer For i = 0 To UBound(oldNames) Dim style As Style Set style = ActiveDocument.Styles(oldNames(i)) style.RenumberList oldNames(i), newNames(i) Next i End Sub |
#2
|
|||
|
|||
![]() Code:
style.RenumberList oldNames(i), newNames(i) If you explain what it is you are trying to do, perhaps someone can help you. |
#3
|
|||
|
|||
![]()
rename oldNames with newNames
|
#4
|
|||
|
|||
![]()
So long as you are not attempting to rename built-in styles that's as simple as
Code:
style.Name = newNames(i) |
#5
|
|||
|
|||
![]() Code:
Sub RenameCharacterStyles() Dim oldNames As Variant oldNames = Array("Old Style 1", "Old Style 2", "Old Style 3") Dim newNames As Variant newNames = Array("New Style 1", "New Style 2", "New Style 3") Dim i As Integer For i = 0 To UBound(oldNames) Dim style As Style Set style = ActiveDocument.Styles(oldNames(i)) style.Name = newNames(i) Next i End Sub |
#6
|
|||
|
|||
![]()
Either the style you are attempting to rename doesn't exist in the ActiveDocument, or you are trying to rename a built-in style, which isn't possible.
You need to add some error checking, for example: Code:
Sub RenameCharacterStyles() Dim oldNames As Variant oldNames = Array("Old Style 1", "Old Style 2", "Old Style 3") Dim newNames As Variant newNames = Array("New Style 1", "New Style 2", "New Style 3") Dim i As Integer Dim sty As Style For i = 0 To UBound(oldNames) Set sty = ActiveDocument.Styles(oldNames(i)) If Not sty Is Nothing Then If Not sty.BuiltIn Then sty.Name = newNames(i) End If Next i End Sub |
#7
|
|||
|
|||
![]()
compile error
on this line Code:
If Not sty.BuiltIn Then sty.Name = newNames(i) |
#8
|
|||
|
|||
![]() Quote:
Code:
If Not sty.BuiltIn Then sty.NameLocal = newNames(i) |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Kindly help references list | balavaka | Word VBA | 1 | 02-11-2022 04:37 AM |
Huge Mistake! | markg2 | Excel | 2 | 05-12-2014 08:05 AM |
![]() |
alexcj37 | Word | 1 | 02-07-2014 08:25 PM |
![]() |
Twene | Excel | 1 | 11-20-2011 02:18 AM |
![]() |
SyedaAdil | Office | 1 | 11-04-2009 08:15 AM |