Make it in a sub and pass the requirements as arguments.
e.g.
Private Sub CommandButton1_Click()
Call HiLiteWord(ActiveCell, Range("A1").Value)
End Sub
Private Sub HiLiteWord(argRange As Range, argWord As String)
Dim StartPos As Long
With argRange
StartPos = InStr(1, .Value, argWord)
If StartPos = 0 Then
MsgBox Chr(34) & argWord & Chr(34) & " was not found in cell " &
argRange.Address
Exit Sub
End If
.Select
SendKeys "{F2}"
SendKeys "{LEFT " & Len(.Value) - StartPos + 1 & "}"
SendKeys "+{RIGHT " & Len(argWord) & "}"
End With
End Sub
NickHK
"Westman" wrote in message
...
Hi NIck,
Thanks for your reply. The codes work like a charm. But I think it is
useful
only when you know what word to find or grab, is it? Right now I'm
developing
a thesaurus for excel and (supposedly) it can find synonym(s) for any word
that I have selected. In your codes, you have define which word should be
search for. And I dont have any clue how to modified those code to make it
get any word at any cell in Excel.
Westman
"NickHK" wrote:
AFAIK, the only way in VBA is with SendKeys:
Private Sub CommandButton1_Click()
Dim StartPos As Long
Const WordToHiLite As String = "eat"
Const RangeToSearch As String = "B6"
With Range(RangeToSearch)
StartPos = InStr(1, .Value, WordToHiLite)
If StartPos = 0 Then Exit Sub
.Select
SendKeys "{F2}"
SendKeys "{LEFT " & Len(.Value) - StartPos + 1 & "}"
SendKeys "+{RIGHT " & Len(WordToHiLite) & "}"
End With
End Sub
NickHK
"Westman" wrote in message
...
Hi,
I'm facing a problem in developing my excell addin. How do I select
just
one
word from a sentences in a single cell? For example:-
I like to eat fried chicken. -- This sentence is in a cell.
Right now, I just want to select word "eat" from the above sentence.
Is
this
posible? If posible, how do I accomplish that?
Regards,
Westman