Ross Webb
08-26-2014, 06:30 PM
I would like to put in a series of incrementing numbers in specific places in a document. For example, if I have the marker "\v" scattered throughout a text I would like to add a '1' to the first one like "\v 1 ", and "\v 2 " at the next instance, and so forth.
An added complication - which seems to be the downfall of my experiments - is that it needs to happen only within a selection of the available text in a document.
Whith my macro below, on the first replace, the selection is removed, and thus(?) the macro stops. Whatever I've tried I can't get the replace value to increment, and have the macro continue.
So far I have:
Sub Increment_Verse_Number()
Dim iNextVerse As Integer
Dim sReplaceText As String
iNextVerse = 1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
sFindText = "\v "
sReplaceText = "\v" + Str$(iNextVerse) + " "
iNextVerse = iNextVerse + 1
Selection.Find.Text = sFindText
Selection.Find.Replacement.Text = sReplaceText
Selection.Find.Execute Replace:=wdReplaceOne
End With
End Sub
Thanks.
An added complication - which seems to be the downfall of my experiments - is that it needs to happen only within a selection of the available text in a document.
Whith my macro below, on the first replace, the selection is removed, and thus(?) the macro stops. Whatever I've tried I can't get the replace value to increment, and have the macro continue.
So far I have:
Sub Increment_Verse_Number()
Dim iNextVerse As Integer
Dim sReplaceText As String
iNextVerse = 1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
sFindText = "\v "
sReplaceText = "\v" + Str$(iNextVerse) + " "
iNextVerse = iNextVerse + 1
Selection.Find.Text = sFindText
Selection.Find.Replacement.Text = sReplaceText
Selection.Find.Execute Replace:=wdReplaceOne
End With
End Sub
Thanks.