Find Object to fix text lists and start of paragraphs
I'm trying to write a macro to convert text lists copied from .txt files into real lists in Word. For example, replace the text "1. My first list item" with a true numbered list style so that Word will handle the numbering, e.g. "1. "
The macro is almost working, but if my text contains the characters "1. " somewhere in the paragraph, it will replace it. I only want to replace the "1. " at the START of paragraphs. It also doesn't work if the number is greater than 1 digit, e.g. "29.". Does anyone know how to fix this code to work!?
Code:
With myRange.Find
'REPLACE THE PREFIX ONLY
.Text = "([1-9]. )(*[^13])"
'SET THE STYLE
.Replacement.Style = "My Numbered List Style"
'REPLACEMENT TEXT IS EVERYTHING AFTER THE PREFIX "- "
.Replacement.Text = "\2" '"\2" refers to the second grouping in the find text above
.MatchWildcards = True
.Execute Format:=True, Replace:=wdReplaceAll
End With