Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-15-2022, 11:43 PM
balavaka balavaka is offline kindly help where i mistake Windows 10 kindly help where i mistake Office 2013
Novice
kindly help where i mistake
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default kindly help where i mistake


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
Reply With Quote
  #2  
Old 12-16-2022, 01:54 AM
Italophile Italophile is offline kindly help where i mistake Windows 11 kindly help where i mistake Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Code:
style.RenumberList oldNames(i), newNames(i)
The function RenumberList does not exist.

If you explain what it is you are trying to do, perhaps someone can help you.
Reply With Quote
  #3  
Old 12-16-2022, 02:05 AM
balavaka balavaka is offline kindly help where i mistake Windows 10 kindly help where i mistake Office 2013
Novice
kindly help where i mistake
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default

rename oldNames with newNames
Reply With Quote
  #4  
Old 12-16-2022, 04:40 AM
Italophile Italophile is offline kindly help where i mistake Windows 11 kindly help where i mistake Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by balavaka View Post
rename oldNames with newNames
So long as you are not attempting to rename built-in styles that's as simple as

Code:
style.Name = newNames(i)
Reply With Quote
  #5  
Old 12-16-2022, 09:10 AM
balavaka balavaka is offline kindly help where i mistake Windows 10 kindly help where i mistake Office 2013
Novice
kindly help where i mistake
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default I try this too but no changes

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
Reply With Quote
  #6  
Old 12-16-2022, 09:50 AM
Italophile Italophile is offline kindly help where i mistake Windows 11 kindly help where i mistake Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

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
Reply With Quote
  #7  
Old 12-16-2022, 10:10 AM
balavaka balavaka is offline kindly help where i mistake Windows 10 kindly help where i mistake Office 2013
Novice
kindly help where i mistake
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default still it shows

compile error

on this line

Code:
If Not sty.BuiltIn Then sty.Name = newNames(i)
Reply With Quote
  #8  
Old 12-16-2022, 11:21 AM
Italophile Italophile is offline kindly help where i mistake Windows 11 kindly help where i mistake Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by balavaka View Post
compile error

on this line

Code:
If Not sty.BuiltIn Then sty.Name = newNames(i)
Sorry that should be
Code:
If Not sty.BuiltIn Then sty.NameLocal = newNames(i)
Reply With Quote
Reply



Similar Threads
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
kindly help where i mistake Kindly repair these .docx file alexcj37 Word 1 02-07-2014 08:25 PM
kindly help where i mistake Kindly help me answer these questions Twene Excel 1 11-20-2011 02:18 AM
kindly help where i mistake kindly fix my problem its urgent! SyedaAdil Office 1 11-04-2009 08:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft