C
cas4
I'm doing a basic search and replace on a Word Document using VB6. I'm searching for wildcards that have the format <%wildcard%> and replacing it with text from a database. The problem is, when the .Execute command is called on the range object, it returns true, but the range still conatains text from the entire document (instead of only containing text that was searched on). Here is the code I'm using:
WildCardFound = True
Do While WildCardFound
Set rng1 = doc.Content
Set rng2 = doc.Content
With rng1.Find
.ClearFormatting
.Text = "<%"
If .Execute = True Then
With rng2.Find
.ClearFormatting
.Text = "%>"
If .Execute = True Then
If rng1.Start < rng2.Start Then
WildCard = doc.Range(rng1.End, rng2.Start).Text
Set rng3 = doc.Range(rng1.Start, rng2.End)
rng3.Text = IIf(IsNull(rec.Fields(WildCard).value), "", rec.Fields(WildCard).value)
If Err.Number <> 0 Then
MsgBox "Field name " & WildCard & " is invalid, unable to continue", vbInformation, "Invalid Field"
LoadReport = False
GoTo CleanUp
End If
Else
WildCardFound = False
End If
Else
WildCardFound = False
End If
End With
Else
WildCardFound = False
End If
End With
Loop
I'm running WinXP and Office XP with all the SP's and updates. Since this code did work several months ago, could a SP (Windows or Office) be the cause of this behavior? If anyone has come across this, please let me know.
Thanks in advance.
WildCardFound = True
Do While WildCardFound
Set rng1 = doc.Content
Set rng2 = doc.Content
With rng1.Find
.ClearFormatting
.Text = "<%"
If .Execute = True Then
With rng2.Find
.ClearFormatting
.Text = "%>"
If .Execute = True Then
If rng1.Start < rng2.Start Then
WildCard = doc.Range(rng1.End, rng2.Start).Text
Set rng3 = doc.Range(rng1.Start, rng2.End)
rng3.Text = IIf(IsNull(rec.Fields(WildCard).value), "", rec.Fields(WildCard).value)
If Err.Number <> 0 Then
MsgBox "Field name " & WildCard & " is invalid, unable to continue", vbInformation, "Invalid Field"
LoadReport = False
GoTo CleanUp
End If
Else
WildCardFound = False
End If
Else
WildCardFound = False
End If
End With
Else
WildCardFound = False
End If
End With
Loop
I'm running WinXP and Office XP with all the SP's and updates. Since this code did work several months ago, could a SP (Windows or Office) be the cause of this behavior? If anyone has come across this, please let me know.
Thanks in advance.