Re: Scripting Excel, oh the troubles...
Re: Scripting Excel, oh the troubles...
- Subject: Re: Scripting Excel, oh the troubles...
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 04 Oct 2002 17:55:22 -0700
On 10/4/02 5:30 PM, "Patrick S. Page-McCaw" <email@hidden> wrote:
>
Sometimes my Excel scripts work and sometimes they don't. Usually
>
they fail with :
>
>
"-1708 Unable to get the Select property of the ... class"
>
>
Where the class can be one of many things. Sometimes manually
>
clicking on Excel and going back to the script solves the trouble,
>
but not always.
>
>
In this case, the error arises from selecting in the Range class. It
>
comes from a call to
>
>
on pasteXLData(theBook, theSheet, theRange)
>
tell application "Microsoft Excel"
>
Activate
>
Select Range theRange of Sheet theSheet of Workbook theBook
>
Paste
>
end tell
>
end pasteXLData
>
>
>
but, a preceding call to copyXLData(...) with the same syntax worked
>
just fine. The Range is a valid range, the space being pasted to is
>
empty etc. In fact, in a repeat loop the same handler will work the
>
first time through but bail (with -1708) the next run through.
>
>
Clearly, I don't understand Selection properties. But what am I missing?
>
Probably only ranges in the frontmost sheet can be selected. But you're only
Activating Excel, you're not bringing thSheet to the front before you try to
select a range in it. Does this work?:
on pasteXLData(theBook, theSheet, theRange)
tell application "Microsoft Excel"
Activate Sheet theSheet of Workbook theBook
Select Range theRange of Sheet theSheet of Workbook theBook
Paste
end tell
end pasteXLData
But why are you using this copy, select and paste method anyway? Wouldn't
this be better:
on replaceXLData(theBook, theSheet, theRange, theNewData)
tell application "Microsoft Excel"
-- Activate Sheet theSheet of Workbook theBook --only if you want to
see it
Set Value of (Range theRange of Sheet theSheet of Workbook theBook)
to theNewData
end tell
end replaceXLData
The format of theNewData should be a list of lists, each component list
being the new data for a row. This may work even for styled text if you can
set each cell value as Unicode text or styled text. But maybe it's easier
for you to get your data into the clipboard than to get it by script.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.