Microsoft Word find and replace, getting the number of found item?

Hi,

I have a script that does the replacing of a certain character before import in InDesign. If I do this with the UI in Word, Word tells me how many items it found. When I do it by script, I’d like to be able to get the same info as to how many time the character in question was found but I can’t figure it out.


tell application "Microsoft Word"
	set myResult to find object of selection
	tell myResult
		execute find find text "^~" replace with "-" replace replace all
	end tell
end tell

Any pointers?

I’ve tried to use the count command on myResult. I’ve also tried to make a variable of excecute find text and count that, but nothing works.

TIA!

These modifications to your code should do the trick.


tell application "Microsoft Word"
	activate
	set theCounter to 0
	set myResult to find object of selection
	tell myResult
		set findResult to true
		repeat until not findResult
			set findResult to execute find find text "^~" replace with "-" replace replace one
			if findResult then set theCounter to theCounter + 1
			tell application "System Events" to keystroke (ASCII character 29)
		end repeat
	end tell
	display dialog "Replacement occured " & theCounter & " times."
end tell