i have some code (shown below) that i got of a site, it allows me to pass in a string, findstring and replace string and it will replace only a full word if it is found. the issue i am having is i have words that have a minus sign behind it and it is treating it like a seperate word.
for example
Howdy Howdy-1
When i tell it to replace Howdy with doodie, it replaces both Howdy and Howdy-1 with doodie and doodie-1 respectively. I want it to replace the one word but not the one that has -1 or any other symbol behind the word like Howdy#1
Is this possible. In my code howdy and doodie are coming from cells in a spreadsheet
function that is doing the replace
Public Function RegExpReplaceWord(ByVal strSource As String, ByVal strFind As String, ByVal strReplace As String) As String
' Purpose : replace [strFind] with [strReplace] in [strSource] '
' Comment : [strFind] can be plain text or a regexp pattern; '
' all occurences of [strFind] are replaced '
'requires reference to Microsoft VBScript Regular Expressions '
'Dim re As RegExp '
'Set re = New RegExp '
'late binding; no reference needed '
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.IgnoreCase = True ' <-- case insensitve
re.Pattern = "\b" & strFind & "\b"
RegExpReplaceWord = re.Replace(strSource, strReplace)
Set re = Nothing
End Function