Re: Excel question
Re: Excel question
- Subject: Re: Excel question
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 01 Apr 2006 09:53:31 -0800
- Thread-topic: Excel question
Title: Re: Excel question
On 4/1/06 8:50 AM, "Antonio Palluan" <email@hidden> wrote:
Hi everybody, I'm Antonio and I'm new in this list, nice to meet you all!
I'm an absolute beginner with applescript but I find it very attractive and I think I'll spend lot of time studying it... I'm descovering the potential...
So, maybe some times I'll ask you some suggestions ... Like this.. :-)
I've got an excel file with a list of numbers and names in the cells. For example:
A B
1 ELEN 12580
2 MARK 12568
3 PHIL 45622
In excel I want to find for example the cell Phil and read the number that is on the right of it...
Well.. very simple... It's two days that I'm trying to do that!!! :-(
tell application "Microsoft Excel"
set marc to find range "$a:$a" what "mark"
set row to get first row index of mark
set targetcell to "[Fattdettagl.xls]Foglio1!$B$" & row
....
end tell
well I'm not able to receive a target cell with the right range...
How would you do it??
Be patient, probably it is a stupid question but... be comprehensive :-)
- Your main problem here is that you set the variable for the range to 'marc' (with a "c") and then in the next line you're looking for the first row index of 'mark' (with a "k"). That's going to error.
- Once you clear that up, in the second line, you cannot use the word 'row' as a variable name, since it's a class name in Excel. I don't understand how you even got that line to compile - here I get "access not allowed" error. I think you've probably cheated in writing to the mailing list - you probably used a different word (maybe the Italian for 'row'?). As long as you use an acceptable word that's not a reserved keyword, that line works and returns 3.
- Then in line 3, there are two problems. First, you don't need to include the name of the file. (The reason you've been getting that when checking for results is that you have not included any identification for the worksheet anywhere. You really ought to be directing everything to 'of active sheet'. It's working anyway, since that's what Excel will coerce to.)
- Second, you don't just need the targetCell's text name, you need the actual cell, right?
tell application "Microsoft Excel"
set mark to find range "$a:$a" what "mark"
set theRow to get first row index of mark
set targetcellName to "$B$" & theRow
--> "$B$3"
But if you want to do anything with that, you actually need the cell, not just the name. To get that, you need some parentheses:
set targetcellName to cell ("$B$" & theRow)
Once you have the result 3 from the previous line, you need to use it correctly as a string "3": AppleScript will coerce the integer (number) 3 to "3" following the string "$B$", but if you put the class 'cell' in front, you need to make sure that it knows what to coerce. If you omit the () parentheses, Applescript would try to make a 'cell "$B$" an coerce that to the number 3' and you'll get an error because the first part doesn't make a cell. Anyway, here's what you want:
tell application "Microsoft Excel"
tell active sheet
set mark to find range "$a:$a" what "mark"
set theRow to first row index of mark
set targetcell to cell ("$B$" & theRow)
end tell
end tell
--> cell "$B$3" of active sheet of application "Microsoft Excel"
The 'tell active sheet' is optional because Excel will do the right thing anyway without it.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden