Article ID: 109330
Article Last Modified on 1/18/2007
'=============================================================
' Declarations section of the module
'=============================================================
Option Explicit
Function Replace(ByVal Valuein As String, ByVal WhatToReplace As _
String, ByVal Replacevalue As String) As String
Dim Temp as String, P As Long
Temp = Valuein
P = Instr(Temp, WhatToReplace)
Do While P > 0
Temp=Left(Temp, P-1) & Replacevalue & _
Mid(Temp, P+Len(WhatToReplace))
P = InStr(P + Len(Replacevalue), Temp, WhatToReplace, 1)
Loop
Replace = Temp
End Function
Valuein: "This is a Sample"
WhatToReplace: "Sample"
ReplaceValue: "Test"
Note that the function Replace("This is a Sample","Sample","Test")
returns:
Additional query words: substitute
Keywords: kbhowto kbprogramming KB109330