Here is a useful function that gives 2 inputboxes
asking for what to find and what to replace it with.
The function uses a textbox, but can be modified for a Richtextbox too. Just stick it in the code window for the current form and call the function reps.
Private Function ReplaceString()
Dim sFind As String, sReplace As String
Dim lStart As Long
Find$ = InputBox("Find what?", "Find and Replace sequence")
sReplace = InputBox("Replace with:", "Find and Replace sequence")
lStart = InStr(1, Text1.text, sFind, vbTextCompare)
If lStart = -1 Then
MsgBox "No matches found", vbInformation, "Sorry"
Else
Text1.SelStart = res - 1
Text1.SelLength = Len(sFind)
Text1.SelText = sReplace
End Function
Comments