I’m trying to copy a range of cells from 1 workbook to another, but it does not work. No error messages displayed. This is my script:
tell application "Microsoft Excel"
activate
set myMainWorkbook to open "/Users/XXX/Desktop/Workbook-Main.xlsx" without dialog
set myOtherWorkBook to open "/Users/XXX/Desktop/Workbook-Other.xlsx" without dialog
copy range (range "B1:D1") of active sheet of myOtherWorkBook
close active workbook
tell active sheet of myMainWorkbook
paste special (range "B2:D2") what paste values
end tell
end tell
Funny thing is, in the Finder I can see that the range from myOtherWorkBook is copied (Edit > Clipboard).
Also, the correct range is selected in myMainWorkbook, but the values are not pasted.
When I manually select Edit > Paste in Excel, then the cells get pasted.
The cells just contain some text.
I’m on 10.11.5 and am using Excel 15.23.2 (160624). Any help much appreciated!
tell application "Microsoft Excel"
activate
open "/Users/XXX/Desktop/Workbook-Main.xlsx" without dialog
set myMainWorkbook to active workbook
open "/Users/XXX/Desktop/Workbook-Other.xlsx" without dialog
set myOtherWorkBook to active workbook
tell myOtherWorkBook
activate
copy range (range "B1:D1") of active sheet
close myOtherWorkBook
end tell
tell worksheet 1 of myMainWorkbook
activate
paste special (range "B2:D2") what paste values
end tell
end tell
Thanks, but does not work for me. Same result: correct range is copied (I can see it in the Clipboard), correct range is selected in the target spreadsheet, but values do not get pasted.
I copied the code from my reply to your first post about this paste problem, changed the username to be appropriate for my computer in the file path, and it ran like a charm. Did you notice that the capitalization is different for “myMainWorkbook” and “myOtherWorkBook”? Could it be something as simple as that?
I got interested in your post because of the use of the paste special. Paste special does operate differently than the solution you have arrived at.
I had fun anyway. Good luck on your optimum solution!