Это автоматически определит, находится ли пробел перед или после строки, и будет действовать соответствующим образом.
Public Function SmartQuotes(ByVal someString As String) As String
someString = " " + someString + " "
Dim oldstring = someString
someString = smarten(someString, "'"c, "‘"c, "’"c)
someString = smarten(someString, """"c, Chr(147), Chr(148))
If oldstring = someString Then
Return Trim(someString)
Else
Return SmartQuotes(someString)
End If
End Function
Public Function smarten(ByVal someString As String, ByVal original As Char, ByVal left As Char, ByVal right As Char) As String
If someString.Contains(original) Then
Dim index = someString.IndexOf(original)
If leftQuoteorRightquote(someString, index) Then
someString = someString.Remove(index, 1).Insert(index, left)
Else
someString = someString.Remove(index, 1).Insert(index, right)
End If
End If
Return someString
End Function
Public Function leftQuoteorRightquote(ByVal somestring As String, ByVal index As Integer) As Boolean
If somestring.Substring(index - 1, 1) = " " And somestring.Substring(index + 1, 1) <> " " Then
Return True
Else
Return False
End If
End Function