How to use the function for find some text?

A

avkokin

Hello.
Mr. Allen Wyatt publish code of one function which provide replace one
text to other (http://wordtips.vitalnews.com/Pages/
T000811_Replacing_Text_in_a_Macro.html). However I can't call it into
macro. How to correct take advantage of the opportunity this function?
That is this function and my macro:
Function RepText(sIn As String, sFind As String, sRep As String) As
String
Dim x As Integer
x = InStr(sIn, sFind)
While x > 0
sIn = Left(sIn, x - 1) & sRep & Mid(sIn, x + Len(sFind))
x = InStr(sIn, sFind)
Wend
RepText = sIn
End Function

Sub findWord()
sIn = Selection.Text
sFind = "the"
sRep = "of"
End Sub

Thank you for your tips.
 
H

Helmut Weber

Hi Anton,

like that:

Sub findWord()
Selection.Text = RepText(Selection.Text, "The", "Of")
End Sub

Not that this is case sensitive.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
H

Helmut Weber

Note that this is case sensitive.
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top