Find & Replace - Microsoft Word documents

Hi,

I’m writing an AppleScript to automate a text find/replace in Microsoft Word. I’d love for the operation to take place in all open documents at the same time.

The “find object” of the “text object” of a document has a boolean property called “all documents”. The “find object” is supposed to be the AppleScript version of the preferences that one is able to set using Word’s “Replace” dialog. I succeeded at setting “all documents” to true, however, when I attempted to run the operation using Word’s “execute find” command, it returned an error: “access not allowed”.

Am I missing something? Here’s the script I’m testing, this simply replaces all hyphens with non-breaking hyphens (I would love it if the script operated on ALL open documents). This assumes that there are multiple docs open, any feedback appreciated! Thanks :slight_smile:

tell application "Microsoft Word"
	set CurrentFindObject to find object of text object of active document
	set all documents of CurrentFindObject to true
	execute find CurrentFindObject find text "-" replace with "^~" replace replace all
end tell

As already noted, the Code Exchange forum is for posting full snippets/solutions. Please use the other forums for help requests.

This thread will be moved.

My apologies and thanks, Bruce. I’ll look for my post under the general AppleScript/OSX category.