osx - Issue saving a excel workbook in applescript -
first post here goes...
i trying write applescript copy sheet existing workbook new workbook, save new workbook single sheet in, attach workbook email.
i relatively new applescript have managed user interaction using cocoadialog , script create new workbook copy sheet on problems start.
i create new workbook fine , set name of workbook variable call later. copy sheet the var set earlier , sheet copied seems new workbook, when save workbook, save in correct place correct filename blank 1 sheet called sheet1 in workbook called sheet1. enough of explanation, here code...
set choice 1 set tabnames "" repeat until (choice = 2) --cocoadialog dropdownbox target excel workbook set filechoice paragraphs of (do shell script "/applications/cocoadialog.app/contents/macos/cocoadialog" & " fileselect --title 'this fileselect' --text 'pick files andor directories' --with-directory $home/dropbox/business/current/") tell application "microsoft excel" open filechoice set sourceworkbook workbook (get name of active workbook) set nooftabs count of worksheets of active workbook --get numer of tabs in target spreadsheet repeat x 1 nooftabs --get tab names set tabnames name of every sheet end repeat set selectedtabname (choose list tabnames) string --get user choose tab copy set destworkbook make new workbook --create new workbook set destworkbook workbook (get name of active workbook) tell destworkbook --get count of tabs set lastsheet sheet (count of sheets) end tell tell sourceworkbook set sourcesheet sheet selectedtabname copy worksheet sourcesheet after lastsheet of workbook destworkbook --copy sourcesheet new workbook end tell tell destworkbook --get save path , add filename set selectedpath paragraphs of (do shell script "/applications/cocoadialog.app/contents/macos/cocoadialog" & " fileselect --title 'select folder save to' --text --with-directory $home/dropbox/business/timesheets/2015/ --select-only-directories") & "/jml timesheet " & selectedtabname string set destworkbookname (posix file selectedpath) string save workbook destworkbook filename destworkbookname file format workbook normal file format overwrite yes --save new workbook end tell end tell set choice 2 end repeat
what doing wrong? need sort bit out before can move on wrapping , putting workbook email attachment.
thanks in advance
jez
jez m-l
the following copy sheet worked in local sample yosemite , excel 2011 mac. can substitute hard-coded file names (wkbksrcname , wkbktargname) dialogs or whatever see fit:
set wkbkpath (posix path of (run script "path desktop")) text set wkbksrcname "clasew-ex5-sample1a.xlsx" set wkbktargname "sample-target.xlsx" tell application "microsoft excel" launch local fullsrcfile, fulltargfile, srcsheet, lasttargsheet, wkbksrc, wkbktarg set fullsrcfile (wkbkpath & wkbksrcname) open fullsrcfile set wkbksrc workbook wkbksrcname set srcsheet sheet 1 of wkbksrc set wkbktarg make new workbook set lasttargsheet sheet (count of sheets) of wkbktarg copy worksheet srcsheet after lasttargsheet tell wkbktarg set fulltargfile (posix file wkbkpath & wkbktargname) text save workbook filename fulltargfile overwrite yes end tell end tell
this may useful fit logic.
Comments
Post a Comment