In my macro i have to handle some variable string with single quote, no problem for manipulate them but at a moment this break my instructions, i try to escape them with this function but i get an "incorrect property value" error. Im not sure this is the function that i need. I have try to use instr() and mid() but no result.
Code: Select all
name = Replace(name, chr(39), "\'")
Function Replace(removeApostrophe As String, Search As String, NewPart As String)
Dim Result As String
Dim StartPosition As Long
Dim CurrentPosition As Long
Result = ""
StartPosition = 1
CurrentPosition = 1
If Search = "" Then
Result = removeApostrophe
Else
Do While CurrentPosition <> 0
CurrentPosition = InStr(StartPosition, removeApostrophe, Search)
If CurrentPosition <> 0 Then
Result = Result + Mid(removeApostrophe, StartPosition, _
CurrentPosition - StartPosition)
Result = Result + NewPart
StartPosition = CurrentPosition + Len(Search)
Else
Result = Result + Mid(removeApostrophe, StartPosition, Len(removeApostrophe))
End If ' Position <> 0
Loop
End If
Replace = Result
End Function