TPE

http://bayanbox.ir/view/263405954590585756/2mobile.png

Tavvafi@gmail.com


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

Sub TheCatInTheHat()

Dim oTextRange As TextRange
Dim OriginalString As String
Dim NewString As String
Dim FindThis As String ' what string are we looking for?
Dim SubstituteThat As String ' what do we replace it with

FindThis = "XXXXXX"
SubstituteThat = "yada yada yada"

' Get a reference to the text you want to manipulate:
' I'm just grabbing the current selection
' You'd want to do this differently
Set oTextRange = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange
OriginalString = oTextRange.Text

' Is the target string part of the text? If not, bug out.
If InStr(OriginalString, FindThis) = 0 Then
Exit Sub
End If

' Get the portion of the string up to but not including where FindThis starts
NewString = Mid$(OriginalString, 1, InStr(OriginalString, FindThis) - 1)

' Add the substitute string
NewString = NewString & SubstituteThat

' Add the portion of the original string after but not including FindThis
NewString = NewString & Mid$(OriginalString, InStr(OriginalString, FindThis) + Len(FindThis))

' Uncomment this, comment out the next if you want to see the result w/o changing the original
'MsgBox NewString

oTextRange.Text = NewString

End Sub