Counting every non-breaking hyphen in a Word document

Hi,

I’m trying to count the number of non-breaking hyphens in a word document. The reason is, I’m replacing those non-breaking hyphens with regular hyphens with AppleScript, but I’d like to have a count of how many were found in the documents. Right now, the only value I can get is if the execute find is true or false, but not the number of items it found. If you do the same thing with the user interface, you get the number of found item, so there must be a way to get that, but I can’t seem to find it.
Here’s what I’ve got:


tell application "Microsoft Word"
	set myResult to find object of selection
	set myFinditem to execute find myResult find text "^~" wrap find find continue replace with "-" replace replace all
	if myFinditem is true then
		display dialog "There were some non-breaking space in the document." buttons "OK" default button "OK"
	else
		display dialog "There were NO non-breaking space in the document." buttons "OK" default button "OK"
	end if
end tell

Thanks for any help:-)

Here’s how to do it in Word Visual Basic:
https://word.tips.net/T003788_Counting_the_Instances_of_a_Text_String.html

Here is an unsophisticated, brute force method in Applescript that assumes your non-breaking hyphens are em dashes.

property emDash : "—" as text

tell application "Microsoft Word"
	activate
	select active document
	copy object selection
end tell

set myText to the clipboard

set theDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to emDash
set theCount to (count myText's text items) - 1
set AppleScript's text item delimiters to theDelims

activate

display dialog "The number of emDashes is " & theCount