jnorman
07-15-2007, 03:53 PM
Hi all,
I'm trying to find a way to find several numbers within a word doc, add 1 to that number, and replace the total. I'm having a problem because the numbers are not in a designated field.
For instance, within a table cell, there is much text, one or more instances of text including "#1, #4, etc." Each instance of #x, needs to be replaced with #x+1 on a daily basis. I've tried writing some code, shown below:
Sub Test190()
Dim oRng As Range
Dim sRpl As String
Dim bFnd As Boolean
Dim iNum As Integer
Set oRng = ActiveDocument.Range
sRpl = "#"
With oRng.Find
.Text = "(#)([0-9]{1,})"
With .Replacement
.Text = sRpl & (iNum + 1)
.Font.Name = "Arial"
.Font.Size = 7.5
End With
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
If Not .Found Then
MsgBox "Searchtext not found"
End If
End With
End Sub
This code has the variable iNum, which, in this instance is not defined. I'm having a problem getting the text found into an integer form that can be manipulated.
I'm a newbie at vba, so any help is appreciated.
I'm trying to find a way to find several numbers within a word doc, add 1 to that number, and replace the total. I'm having a problem because the numbers are not in a designated field.
For instance, within a table cell, there is much text, one or more instances of text including "#1, #4, etc." Each instance of #x, needs to be replaced with #x+1 on a daily basis. I've tried writing some code, shown below:
Sub Test190()
Dim oRng As Range
Dim sRpl As String
Dim bFnd As Boolean
Dim iNum As Integer
Set oRng = ActiveDocument.Range
sRpl = "#"
With oRng.Find
.Text = "(#)([0-9]{1,})"
With .Replacement
.Text = sRpl & (iNum + 1)
.Font.Name = "Arial"
.Font.Size = 7.5
End With
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
If Not .Found Then
MsgBox "Searchtext not found"
End If
End With
End Sub
This code has the variable iNum, which, in this instance is not defined. I'm having a problem getting the text found into an integer form that can be manipulated.
I'm a newbie at vba, so any help is appreciated.