Re: paste special problem
Re: paste special problem
- Subject: Re: paste special problem
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 22 Mar 2002 09:31:49 -0800
On 3/22/02 8:02 AM, "email@hidden" <email@hidden> wrote:
>
i have written a script that copies a screen report from myob into excel,
>
then copies the data from one excel spreadsheet to another. since the
>
original myob report is in a highly stylized format which i don't want to
>
use, when i paste the info into the 2nd excel spreadsheet, i use the paste
>
special command so only the values are pasted.
>
>
in visual basic, the macro command looks like this:
>
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
>
False, Transpose:=False
>
>
i can't figure out how the variables are supposed to be separated in
>
applescript: by brackets, by commas, by lines. . . .
>
>
i notice in applescript that paste special wants to be told a specific
>
destination. since i want the paste to begin at the cell which is active
>
when i invoke the script, i added a string which creates a new name in the
>
active cell called "new." i don't know if this is necessary.
In the Excel AppleScript dictionary, you can tell which parameters are
required - they're the ones with [square brackets] around them. But, more
often than not, even so-called required parameters (no brackets) have
default value, so you don't actually have to list any of them. You'll notice
that even the direct object, which is actually the location, is put into
square brackets here [reference], meaning that you don't have to specify
where you want to paste - it will paste the contents of the clipboard into
the active cell where the cursor is, presumably, if you don't specify
anything else. Normally, you'd just list any parameters, optional or
required, separated only by space with the value following:
PasteSpecial
with nothing following at all _should_ paste the contents of the clipboard
into the active cell;
PasteSpecial PasteType xlValues
but I think you may need to specify the location after all. You will find
ActiveCell as a property of Application (meaning you don't have tom specify
the Worksheet, just like Selection. in VBA) in the Custom Suite, so this
would be safer:
PasteSpecial ActiveCell PasteType xlValues
should do it for that parameter (AppleScript itself knows which data types
are application keywords, parameters, or values, and which are AppleScript
language keywords, etc. If you select AppleScript Formattiing in the Editor
menu of Script Editor (or any applescript editor's preferences), you can set
color and font of different parts of speech to make this clearer.
Boolean parameters are a special case: although you can write
Transpose false
AppleScript will change that to
without Transpose
when you compile, and similarly
with Transpose
for 'Transpose true', so it's simpler to type it in that way yourself. (In
fact, it's better, because you sometimes would need to put (Transpose true)
into parentheses to avoid certain language conflicts at times. With several
booleans of the same false or true value, you'd do this (or AS will do it
for you)
without Transpose and Link
instead of
Transpose false Link false
but either way will work.
So, in your particular case, this should do it:
PasteSpecial ActiveCell PasteType xlValues Operation xlNone without
SkipBlanks and Transpose
Note that you may have trouble pasting from applications outside Excel, or
Office (Word will wok). Office has its own proprietary clipboard and doesn't
seem to recognize the system clipboard. There may be some way to get the
text there.
But why copy and paste at all? AppleScript's 'get' and 'set' for text
usually convert into plain text, and you can always just say 'as string' if
they don't. I don't know if MYOB is AppleScriptable - is it ? - but if not,
there are ways of getting it styled text from the clipboard into plain text
as a variable, outside an Excel tell block. Then you'd just set the value of
the active cell to that variable within an Excel tell block. This might just
work:
set myobText to the clipboard as string
tell application "Microsoft Excel"
Activate
set Value of ActiveCell to myobText
end tell
If that still appears as formatted text, come back. Or try this:
set myobText to the clipboard as string
set styledReco to myobText as record
set plainText to <<class ktxt>> of styledReco
tell application "Microsoft Excel"
Activate
set Value of ActiveCell to myobText
end tell
But instead of << and >>, type option-\ (option backslash) and
option-shift-\ (option shift backslash) to get chevrons (this list server
will mangle it if I do it here).
That will do it for sure, but the simple version probably will too.
--
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.