I have code (as a macro) that I want to locate all instances of oNum in a Word document and then replace it with ascending numbers starting with 1. I am doing document assembly where there can be a varying amount of oNum in each document. I've tried working with If, Then and For, Next, but don't have a firm grasp of VBA yet. This code will replace all oNum with 1, but I can't get the sequential numbering to work. Here's the code:
Sub Find_Count()
'
' Find_Count Macro
' Macro recorded 9/9/2006
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "oNum"
.Replacement.Text = "1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub Find_Count()
'
' Find_Count Macro
' Macro recorded 9/9/2006
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "oNum"
.Replacement.Text = "1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub