S
St!ff M!ttens
the following code returns predictable results:
tell application "Microsoft Excel"
set theSelection to (get selection)
set theSelectedRange to (item 1 of (get areas of (get properties of
theSelection)))
end tell
==>range "'[Workbook1]Sheet1'!$I$23" of application "Microsoft Excel"
now, the Excel dictionary has this entry:
get end: Returns a range object that represents the cell at the end of
the region that contains the source range.
get end range
direction toward the bottom/toward the left/toward the right/toward
the top -- The direction in which to move.
Result: range
So, I would think that the following code would then return 23, but:
tell application "Microsoft Excel"
set theSelection to (get selection)
set theSelectedRange to (item 1 of (get areas of (get properties of
theSelection)))
set theEndRange to first row index of (get end theSelectedRange
direction toward the bottom)
end tell
==>65536
Okay, I think I see what's going on: "Returns a range object that
represents the cell at the end of the region that contains the source
range" means that really all this command is going to do for me is
return the last cell in the worksheet, and what possible use is that to
me?
But wait, the following code returns something different:
tell application "Microsoft Excel"
first row index of (get end (used range of sheet 1 of active
workbook) direction toward the bottom)
end tell
==>10
the result 10, in my case, is exactly what I originally thought the
'get end' command should do. But the source range (in this case, 'used
range of sheet 1 of active workbook') is contained by the entire
worksheet in the same way that the selected range is in the previous
code, isn't it? So why do these two return different results? And more
importantly, how can I get my script to look at the current selection
and determine how many rows it spans?
St!ff
tell application "Microsoft Excel"
set theSelection to (get selection)
set theSelectedRange to (item 1 of (get areas of (get properties of
theSelection)))
end tell
==>range "'[Workbook1]Sheet1'!$I$23" of application "Microsoft Excel"
now, the Excel dictionary has this entry:
get end: Returns a range object that represents the cell at the end of
the region that contains the source range.
get end range
direction toward the bottom/toward the left/toward the right/toward
the top -- The direction in which to move.
Result: range
So, I would think that the following code would then return 23, but:
tell application "Microsoft Excel"
set theSelection to (get selection)
set theSelectedRange to (item 1 of (get areas of (get properties of
theSelection)))
set theEndRange to first row index of (get end theSelectedRange
direction toward the bottom)
end tell
==>65536
Okay, I think I see what's going on: "Returns a range object that
represents the cell at the end of the region that contains the source
range" means that really all this command is going to do for me is
return the last cell in the worksheet, and what possible use is that to
me?
But wait, the following code returns something different:
tell application "Microsoft Excel"
first row index of (get end (used range of sheet 1 of active
workbook) direction toward the bottom)
end tell
==>10
the result 10, in my case, is exactly what I originally thought the
'get end' command should do. But the source range (in this case, 'used
range of sheet 1 of active workbook') is contained by the entire
worksheet in the same way that the selected range is in the previous
code, isn't it? So why do these two return different results? And more
importantly, how can I get my script to look at the current selection
and determine how many rows it spans?
St!ff