Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Find and Replace and Number Problem in Word

Status
Not open for further replies.

jhernon

MIS
Sep 9, 2006
3
US
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. 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
 
You probably want to ask this in the VBA forum, forum707, rather than here in the VB forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top