View Single Post
 
Old 12-06-2021, 09:06 PM
Bikram Bikram is offline Windows 10 Office 2007
Advanced Beginner
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Post Changing list numbering

Greeting to all the members, Recently I tried to change lists. For Example, I changed 1 to a, 2 to be, and so on from style name list1 and similarly changed a to i, b to ii, and so on from list2. The macro I wrote works as expected but the macro that I created is lengthy and I just want to know if that can be shortened so that the macro works efficiently and code would be dynamic.

Sub ChangingNumberslists()
Dim i As Integer
Dim rng As Range
Dim ipara As Long
Dim opara As Paragraph
Dim st As Style

Set rng = ActiveDocument.Range
ipara = rng.Paragraphs.Count
For i = ipara To 1 Step -1
Set opara = rng.Paragraphs(i)
Set st = opara.Range.Style
If opara.Range.Information(wdWithInTable) = False Then
opara.Range.Select
If st = "List1" Then
Selection.Range.ListFormat.ConvertNumbersToText
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=2, Extend:=wdExtend
With Selection.Range.Font
.Name = "Lato heavy"
.Size = 7.5
End With
Select Case Selection.Text
Case "1."
Selection.TypeText Text:="a."
Case "2."
Selection.TypeText Text:="b."
Case "3."
Selection.TypeText Text:="c."
Case "4."
Selection.TypeText Text:="d."
Case "5."
Selection.TypeText Text:="e."
Case "6."
Selection.TypeText Text:="f."
Case "7."
Selection.TypeText Text:="g."
Case "8."
Selection.TypeText Text:="h."
Case "9."
Selection.TypeText Text:="i."
Case "10."
Selection.TypeText Text:="j."
End Select
End If
If st = "list2" Then
Selection.Range.ListFormat.ConvertNumbersToText
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=2, Extend:=wdExtend
With Selection.Range.Font
.Name = "Lato heavy"
.Size = 7.5
End With
Select Case Selection.Text
Case "a."
Selection.TypeText Text:="i."
Case "b."
Selection.TypeText Text:="ii."
Case "c."
Selection.TypeText Text:="iii."
Case "d."
Selection.TypeText Text:="iv."
Case "e."
Selection.TypeText Text:="v."
Case "f."
Selection.TypeText Text:="vi."
Case "g."
Selection.TypeText Text:="vii."
Case "h."
Selection.TypeText Text:="viii."
Case "i."
Selection.TypeText Text:="ix."
Case "j."
Selection.TypeText Text:="x."
End Select

End If
End If


Next
End Sub
Reply With Quote