No, Hilena, that example on p. 50 would _not_ help, it would only confuse
Mark further. It's a poor example - precisely what NOT to do. It should be
fixed. And p. 328 doesn't help either. The correct description is only on p.
336, but without any examples.
The example on p. 50:
set theList to {"Name","Full Name","Path","Installed"}
set value of range "A1
1" to theList
only works because range "A1
1" is a single row. That's what allows the
simple list to work. Properly speaking, it should really be
set theList to {{"Name","Full Name","Path","Installed"}}
or else:
set theList to {"Name","Full Name","Path","Installed"}
set value of range "A1
1" to {theList}
similar to my previous example. Excel is smart about coercing the simple
list to a single-item list of list when you're setting the value of a row,
so that's why this example works. But it's a VERY BAD example, since it;s
demonstrating a silent coercion of the wrong syntax that only works for a
row, not other ranges. Doing that is precisely what errored for Mark!
The WHOLE POINT was that Mark was trying to set the value of a COLUMN. As I
already said, a few times, you then really have to use a list of lists,
where each row's value is a sublist within the outer list. Mark's error was
that he tried to use a simple list, just like this example on p. 50, and IT
DOES NOT WORK FOR A COLUMN, nor for any range other than a row.
Since p. 50 offers the only example, that's exactly what people will try,
and they will continue to be puzzled and get things wrong, because the
example only works for the very special case of setting a single row,
Please read my previous post. As I pointed out there, to set the value of a
range, you need to set a list of lists, For Mark's column, that would be:
{{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}}
For a range three columns wide and four rows deep:
{{11, 21, 31}, {21,22, 23}, {31, 32, 33}, {41, 42, 43}}
For a row, this will work, as it should:
{{"Name","Full Name","Path","Installed"}}
even though you can get away with
{"Name","Full Name","Path","Installed"}
since Excel will silently coerce that for you.
All anyone has to do is to GET the value of a range and you'll see for
yourself:
tell application "Microsoft Excel"
set theList to {"Name", "Full Name", "Path", "Installed"}
set value of range "A1
1" to theList
get value of range "A1
1"
end tell
--> {{"Name", "Full Name", "Path", "Installed"}}
See? Try it on a column, and you'll see how that looks too.
The description on p. 328 is not much better, because it doesn't spell out
that the value of a range is a list of lists. It just avoids the whole issue
by blurring it:
set value of range "A5" of active sheet to ¬
(get value of range "A1" of active sheet)
You can't actually tell what structure the value has here, although this
will copy the value correctly.
***But now go to p. 336.
The definition of the 'value' property of range, on p. 336, IS CORRECT:
"
If the range is a single cell, returns or sets the value of the specified
cell. If the cell is empty, value returns an empty string. If the range
object contains more than one cell, returns a list of values. Each internal
list within the outer list corresponds to a row of cell values. The value of
a single row returns a list containing a single internal list of cell
values.
"
See that
"Each internal list within the outer list corresponds to a row of cell
values."
That's correct. You can work out from that definition that there is a list
of lists. It's not a terribly clear explanation, though. And the final
sentence is correct as well: it explains that there's an outer list
containing a single internal list.
What's missing is some examples. There should be examples of getting and
setting the value of a column, a two-dimensional range, and a row.
And the example on p. 50 should be changed.
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <
http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <
http://macscripter.net/scriptbuilders/>
Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.
PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
From: "Hilena Hailu [MSFT]" <
[email protected]>
Newsgroups: microsoft.public.mac.office.excel
Date: Tue, 28 Feb 2006 19:31:20 -0800
Subject: Re: Scripting Excel: fill column with items of list variable
Hi Mark,
You can read about the Range class on page 328. There is also an example of
what you wanted to do on page 50.
Hope this helps!
--
Hilena Hailu
Macintosh Business Unit
Microsoft Corp.
--------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Mark Aalyson said:
Paul,
I wanted to follow your suggestion and read through the EAR on this topic. I
couldn't find any discussion of the value of a range. I looked through the
reference manual for Excel 2004. Can you point me to a page?