R
Raj
Hi Macro greats !
This macro will parse a document search for string that start as
RAJ-XXX- and appending a running serial number to it so that the
resulting string would be RAJ-XXX-001, RAJ-XXX-002, so on.
The macro works fine when the document is opened for the first time
and the macro is run.
It works everytime I close the document and open it.
If I run the macro the second time, without closing the document, the
macro parses the document twice and renumbers the tags twice, so I get
the tag numbers twice than what is actually there. Basically the Macro
runs twice before hitting the find.found = false statement.
I checked this with display statement.
Any help is welcomed
===========================================================================
Sub FSDTagGenerator()
'
' FSDTagGenerator Macro
' Macro created 08/20/03 by Raj
'
Dim CNT As Integer
Dim pos As Integer
Dim st1 As String
Dim st2 As String
Dim st3 As String
st2 = "RAJ-XXX-"
st1 = st2 + "*>"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = st1
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Selection.Find.Execute
CNT = 0
Do While True
'For CNT = 1 To 1000
CNT = CNT + 1
If CNT < 10 Then
st3 = st2 + "00" + CStr(CNT)
ElseIf CNT < 100 Then
st3 = st2 + "0" + CStr(CNT)
Else
st3 = st2 + CStr(CNT)
End If
Selection.Find.Execute
If Selection.Find.Found = False Then
MsgBox ("No more finds")
Exit Do
End If
Selection.Find.Replacement.Text = st3
With Selection
.Find.Execute Replace:=wdReplaceOne
End With
Loop
End Sub
===========================================================================
This macro will parse a document search for string that start as
RAJ-XXX- and appending a running serial number to it so that the
resulting string would be RAJ-XXX-001, RAJ-XXX-002, so on.
The macro works fine when the document is opened for the first time
and the macro is run.
It works everytime I close the document and open it.
If I run the macro the second time, without closing the document, the
macro parses the document twice and renumbers the tags twice, so I get
the tag numbers twice than what is actually there. Basically the Macro
runs twice before hitting the find.found = false statement.
I checked this with display statement.
Any help is welcomed
===========================================================================
Sub FSDTagGenerator()
'
' FSDTagGenerator Macro
' Macro created 08/20/03 by Raj
'
Dim CNT As Integer
Dim pos As Integer
Dim st1 As String
Dim st2 As String
Dim st3 As String
st2 = "RAJ-XXX-"
st1 = st2 + "*>"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = st1
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Selection.Find.Execute
CNT = 0
Do While True
'For CNT = 1 To 1000
CNT = CNT + 1
If CNT < 10 Then
st3 = st2 + "00" + CStr(CNT)
ElseIf CNT < 100 Then
st3 = st2 + "0" + CStr(CNT)
Else
st3 = st2 + CStr(CNT)
End If
Selection.Find.Execute
If Selection.Find.Found = False Then
MsgBox ("No more finds")
Exit Do
End If
Selection.Find.Replacement.Text = st3
With Selection
.Find.Execute Replace:=wdReplaceOne
End With
Loop
End Sub
===========================================================================