What's wrong with this Excel GUI script

G’day

I’m trying to automate the printing of excel documents. I can use 10 tabs to get to the last page range box, but would prefer to do it more directly.

I’ve use UI browser to find the details of the appropriate text box, but the three methods I’ve tried to set it have failed.

Can anyone set me straight on any mistakes I’ve made please?


tell application "Microsoft Excel"
	activate
	repeat until exists window 1
		delay 0.5
	end repeat
	tell application "System Events" to tell process "Microsoft Excel"
		keystroke "p" using command down
		delay 4
		tell application "System Events" to tell process "Microsoft Excel" to tell window 1
			
			set value of text field 3 of UI element 1 of UI element 6 to 3
			
			select text field 3 of UI element 1 of UI element 6
			keystroke 3
		end tell
		tell window 1
			set value of text field 3 of UI element 1 of UI element 6 to 3
			
			--keystroke return
		end tell
		delay 2
		keystroke "w" using command down
	end tell
end tell

Hi Santa,

why not

tell application "Microsoft Excel" to print out active sheet from 1 to 3

??

G’day Stefan

The number of beers I owe you grows.

While I’m at it, could anyone tell me what’s wrong with this script for Word 2004.

The ‘print’ part is lifted straight from their pdf documentation, but generates an error.

Regards

Santa


tell application "Microsoft Word"
	activate
	print out active window print out range print from to page from 1 page to 3
	delay 2
	close window 1 saving no
end tell

Microsoft Word got an error: active window doesn’t understand the print out message.

Thanks Jacques, that works a treat. :slight_smile:

Santa