Re: Excel Selection
Re: Excel Selection
- Subject: Re: Excel Selection
- From: Stan Cleveland <email@hidden>
- Date: Mon, 30 Oct 2006 13:20:05 -0800
- Thread-topic: Excel Selection
On 10/30/06 12:39 PM, Steven Valenti wrote:
> I want to get the row and column of selected cell or cells. If I use
> this code...
> set MySelection to selection
> ...I get
> --selection of Application "Microsoft Excel" as a result
> Dictionary states the selection returns a Range but I was expecting
> something like "A3" or whatever was selected.
> Is there anyway to return the row and column value of a selection?
On 10/30/06 1:09 PM, Paul Berkowitz wrote:
> Most objects are (as is frequent with AppleScript) passed as references
> rather than being evaluated. That has its advantages: if you want to modify
> the selection, you can. It is a little annoying sometimes that it doesn't
> evaluate to the range-by-address (i.e. range "A10:A15" of worksheet "Name"
> of workbook "File Name.xls"), but you can manipulate it exactly as if it
> did.
Paul is right about the wisdom of directly utilizing the reference to a
cell, rather than trying to use an "A1" or R1C1" address. However, if you
need to know "where" you are in the worksheet, the following should get you
started.
If you're using Excel 2004:
tell application "Microsoft Excel"
set selRow to first row index of selection
set selCol to first column index of selection
end tell
For Excel X, use this:
tell application "Microsoft Excel"
set selRow to Row of Selection
set selCol to Column of Selection
end tell
>From there, if you need an "A1" address, you can convert selCol to the
appropriate letter using a lookup table or a mathematical method.
Stan C.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden