Hello,
Can someone explain me why this script does not work ?
It does not want to active the target workbook. So it copies the values in the source workbook and not in the target one.
tell application “Microsoft Excel”
activate
set source_file to “Macintosh HD:Users:philippedegouville:Documents:projet:script:source.xls”
set target_file to “Macintosh HD:Users:philippedegouville:Documents:projet:Script:cible.xls”
open source_file
open target_file
repeat with i from 1 to 3
activate object workbook source_file
set valeur_source to value of cell i of column 1
activate object workbook target_file
set value of cell (i + 3) of column 1 to valeur_source
end repeat
end tell
Thanks
Model: mac osx
AppleScript: 2,2,1
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)
activating a workbook is not needed, a valid reference is sufficient
tell application "Microsoft Excel"
activate
set source_file to "Macintosh HD:Users:philippedegouville:Documents:projet:script:source.xls"
set target_file to "Macintosh HD:Users:philippedegouville:Documents:projet:Script:cible.xls"
open source_file
set sourceSheet to active sheet of workbook (name of active workbook)
open target_file
set destinationSheet to active sheet of workbook (name of active workbook)
repeat with i from 1 to 3
set value of cell (i + 3) of column 1 of destinationSheet to (get value of cell i of column 1 of sourceSheet)
end repeat
end tell
You can do the same thing (probably faster) with the copy range command
set value of ¬
(get resize (cell 4 of column 1 of destinationSheet) row size 3 column size 1) ¬
to get value of ¬
(get resize (cell 1 of column 1 of sourceSheet) row size 3 column size 1)