View Full Version : Help VBA automatic numbering in Word
lamnbj
05-02-2022, 06:31 AM
I have a document in Word of the form:
Question 1: Chdsh
Question 1: aghj
Lesson 1: ghj
Lesson 2: sagdhj
Is there a way to quickly change the "Question 1, .." and "Lesson 1, ..." to automatic numbering? Thanks everyone
gmaxey
05-03-2022, 05:17 AM
If you created a new list style called say QL List and made the Level 1 number format "Question 1" and the Level 2 number format "Lesson 1" then you could use a find and replace something like this:
Sub A()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "Question [0-9]@: @"
.MatchWildcards = True
While .Execute
oRng.Delete
oRng.Paragraphs(1).Range.Style = "QL List"
oRng.Collapse wdCollapseEnd
Wend
End With
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "Lesson [0-9]@: @"
.MatchWildcards = True
While .Execute
oRng.Delete
oRng.Paragraphs(1).Range.Style = "QL List"
oRng.ListFormat.ListLevelNumber = 2
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
lamnbj
05-03-2022, 06:45 AM
Oh sorry it doesn't work
gmaxey
05-03-2022, 09:49 AM
If is doesn't work then apparently you didn't properly create and define a new list style titled "QL List" or applied the code wrong. "Sorry, it doesn't work" isn't going to get you much help here.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.