Automated Word sequences (in Word 2011)

Hi all.
Long time you see: sorry for this, but as in past, I need your help.

I have many documents .docx builder by Word for Mac 2011 in a Mac with 10.6.6
In any document there are lot of sequences like “Figura X.X” that have to become
“Figura X.1”, “Figura X.2”, “Figura X.3” …

I have build this little script for this (helped by Google)


tell application "Microsoft Word"
	
	set findRange to find object of selection
	set numero to 0
	repeat
		set cap to 2
		set numero to (numero + 1)
		
		set figura to "Figura " & cap & "." & numero
		
		tell findRange
			execute find find text "Figura X.X" replace with figura replace replace one
		end tell
		
		-- if (execute find) is "false" then exit repeat
	end repeat
end tell


I have found and edit this script that find all “Figura X.X” and changed in sequence to “Figura 2.1”, “Figura 2.2”, “Figura 2.3” …

First problem is that the script change ONLY the first sequence, not all. If i change replace one with replace all, all sequence become “Figura 2.1”, tant’s not right.

Second problem is that I’m unable to block the script. How can I bring the answer false of the tell routine and put in a variable?

Tnx for all

Model: iMac
AppleScript: 2.3
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

I’m not very good with word, but I gave it a try. If I have the following word document…

Figura X.X
Figura X.X
Figura X.X
Figura X.X
Figura X.X

This script will replace it to this…

Figura X.1
Figura X.2
Figura X.3
Figura X.4
Figura X.5

tell application "Microsoft Word"
	set findRange to text object of selection
	set numero to 0
	repeat
		set findObject to find object of findRange
		set numero to (numero + 1)
		set figura to "Figura X." & (numero as text)
		
		tell findObject
			execute find find text "Figura X.X" replace with figura replace replace one
			if result is false then exit repeat
		end tell
	end repeat
end tell

I hope that helps. :slight_smile:

Great work!
Everything is fine, thx

Matteo

Glad to help. :slight_smile: