Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 60
Shift:=xlShiftToRight, _
CopyOrigin:=xlFormatFromLeftOrAbove
End With
End With
Here the CopyOrigin argument in VBA has no AppleScript equivalent, so the defaults will rule : " If this argument is omitted, the format is inherited as from the Left or Above depending on whether the shift was to the right or down." So there's no way to specify it in AppleScript, but in this case the result will be exactly the same – xlFormatFromLeftOrAbove.
tell application "Microsoft Excel"
tell active workbook
tell range "A1:A10" of sheet "Sheet2"
copy range
insert into range (get resize row size (count rows) ¬
column size (count columns)) shift shift to right
end tell
end tell
end tell
Deleting a range moves cells up or to the left, depending on what the argument specifies. The following example deletes duplicate rows (based on identical values in the first column). Note that the loop goes from largest row to smallest "backwards" via Step -1, since Excel renumbers the rows after a deletion. Since this what AppleScript always does in its own indexing, you would have to do that anyway (repeat with i from lastRowNum to 1 by -1).
Dim i As Long
With ActiveSheet
For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 2 Step -1
If .Cells(i, 1).Value = .Cells(i - 1, 1).Value Then _
.Cells(i, 1).EntireRow.Delete
Next i
End With
In AppleScript:
tell application "Microsoft Excel"
tell active sheet
set lastRowNum to first row index of ¬
(get end (cell 1 of row (count rows)) direction toward the top)
repeat with i from lastRowNum to 2 by -1
if value of (cell 1 of row i) = value of (cell 1 of row (i - 1)) then
delete entire row of (cell 1 of row i)
end if
end repeat
end tell
end tell
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine