Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fugueink

macrumors newbie
Original poster
Apr 5, 2012
1
0
Hi, all!

I am a very new AppleScripter; I am using it to automate things for Dragon Dictate so I can gradually go hands-free. Therefore I am looking to do some very basic things in Excel 2011.

Right now the problem is clicking the AutoSum button in the Standard toolbar of the active window. I know I have to send things through System Events, but I can't get the following line of the script:

Code:
tell application "Microsoft Excel"
	activate
end tell
tell application "System Events"
	tell process "Microsoft Excel"
		<click the button "AutoSum" of "Standard" of
                  window> 
	end tell
end tell

The portion in the angle brackets is the closest I've come. It told me that access was denied. I've tried dozens of other things, including using "command bar control 2" instead of "AutoSum" (a document at MicroSoft said that was the correct number for that control back in version 2004, and I could find nothing more recent).

I imagine I'm missing something very obvious, but I cannot find it anywhere on the Web. Does anyone here know how to do this?

Thank you!

K

On edit:

OK, I've made a little progress. I found an old app Apple used to make available called UIElementInspector. I discovered that the items I am trying to access are in a few levels. I've now got this:

Code:
tell application "Microsoft Excel"
	activate
end tell
tell application "System Events"
	tell process "Microsoft Excel"
		click button "AutoSum" of group "AutoSum" of tool 
                bar "Standard" of front window
	end tell
end tell

But I get an AppleScript error when I run it that says

System Events got an error: Can’t get tool bar "Standard" of window 1 of process "Microsoft Excel".

I tried calling it "active window" instead of front window, but then the script wouldn't compile.

Any kind souls out there who can point out what I'm doing wrong? ^_^

Thank you!

K
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Use UI Browser

Try to use UI Browser a little gem found here : http://pfiddlesoft.com/uibrowser/UI Browser generates GUI Scripting script statements for you based on your selection of an element and an attribute or action.

Code:
tell application "Microsoft Excel"
	activate
tell application "System Events"
	tell process "Microsoft Excel"
		<click the button "AutoSum" of "Standard" of
                  window> 
	end tell
end tell
end tell

Right now you code will activate Excel. If you want AutoSum to do something you should activate for example a workbook.

Activating a workbook using the activate object command puts the workbook in the active window. The following procedure activates the open workbook named "MyBook.xls."

Code:
tell application "Microsoft Excel" 
    activate 
    activate object workbook "MyBook.xls" 
end tell

Note The activate object command works only if Excel is the active program. When you use the activate object command, you should also use the activate command to ensure that Excel is the active program.


Command: activate object
Activates the object.
Syntax
activate window/sheet/workbook/pane Required. An expression that returns a window, sheet,
workbook, or pane object.
Example
This example activates Sheet1.
activate object worksheet "Sheet1"
This example selects cells A1:C3 on Sheet1 and then makes cell B2 the active cell.
activate object worksheet "Sheet1"
select range "A1:C3" of active sheet
activate object range "B2"
This example activates Book4.xls. If Book4.xls has multiple windows, the example activates the first
window, Book4.xls:1. The application must be activated for this example to run successfully.
activate object workbook "Book4.xls"
 

Attachments

  • Excel2004AppleScriptRef.pdf
    1.7 MB · Views: 341
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.