I have a string like this
\"C://Documents/TestUser/WWW/Help/Files/Move_Help.txt\"
and have to replace Move_Help.txt
Would the technique in the code below meet your requirement?
The intial value of Str is:
C://Documents/TestUser/WWW/Help/Files/Move_Help.txt
The final value is:
C://Documents/TestUser/WWW/Help/Files/Move_Job.txt
The code uses InStrRev to locate the last occurrence of ValueCrnt, if any, If ValueCrnt is present, it replaces that final occurrence with ValueNew.
Option Explicit
Sub Demo()
Dim Pos As Long
Dim Str As String
Dim ValueCrnt As String
Dim ValueNew As String
Str = "C://Documents/TestUser/WWW/Help/Files/Move_Help.txt"
ValueCrnt = "Help"
ValueNew = "Job"
Pos = InStrRev(Str, ValueCrnt)
If Pos > 0 Then
Str = Mid(Str, 1, Pos - 1) & Replace(Str, ValueCrnt, ValueNew, Pos)
End If
Debug.Print Str
End Sub