Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find words containing straight apostrophe (as opposed to curly apostrophe)

Tags:

ms-word

vba

I have inherited a text with words containing apostrophes, some of which are "curly" , and some straight '. In order to process the text I need a reliable search method which will produce only exact matches for my search text.

So far, whenever I search the text for a word containing a straight apostrophe (like he's), Word also returns a match for the same word containing a curly apostrophe (he’s) and I do not want this to happen. I want exact matches with ' straight apostrophes only.

The VBA instruction I'm using is:

MyRange.Find.Execute FindText:=strSearchText, Forward:=True, Format:=False, _
    MatchCase:=True, MatchWholeWord:=True

Can anybody give me a hint?

like image 338
Marcel Avatar asked Dec 14 '25 13:12

Marcel


1 Answers

From VBA's F1 help for the Find.Execute method:

To search for a symbol character, type a caret (^), a zero (0), and then the symbol's character code. For example, "^0151" corresponds to an em dash (—).

For a straight apostrophe this would be ^039. So for example, if you're searching for he's, then you will want

FindText:="he^039s"

This does not find the curly apostrophe equivalent, he’s.

like image 50
Jean-François Corbett Avatar answered Dec 19 '25 05:12

Jean-François Corbett