Select multiple sheets in Excel using Applescript

I have an Excel workbook with multiple worksheets.

I need to copy 2 of the sheets (Report1 and DataX) out to a new workbook.

Report1 has formulas referencing to DataX, and also formulas referencing to other sheets.

The requirement is, for formulas referencing to other sheets, I will break link after copying them to the new workbook. However, the links in Report1 to DataX are to stay.


Tried the following:


--define path of file

tell application "Finder"

set workdir to (get folder of (path to me)) as Unicode text

end tel


set master to Master.xlsx


tell application "Microsoft Excel"

set theSheets to {sheet "Report1" of workbook master, sheet DataX of workbook master}

set outputFile to make new workbook

set display alerts to false

copy worksheet theSheets before sheet "Sheet1" of outputFile --copy the 2 sheets out to new file


tell active workbook

break link name workdir & master type link type Excel links

end tell

end tell


The above does not work because the links in Report1 for DataX were referenced to the original file instead of the new workbook. And after breaking link, the data became static.


How can I do it such that the referencing moves together with the copied sheets?

MacBook Pro with Retina display, OS X Yosemite (10.10.4)

Posted on Jul 8, 2015 3:26 AM

Reply
5 replies

Jul 8, 2015 6:56 PM in response to SGIII

It doesn't work. If I duplicate the entire workbook, there will be no links to break as they are all from the same workbook. However, if I delete the sheets I do not want, the referenced data will have #REF! error.


A possible solution that I can think of now is to still copy the required sheets out, then, in the new workbook where the columns are linked to DataX sheet, find the [filename of the original workbook] and replace with blank.

Jul 9, 2015 8:15 AM in response to lynnlh

lynnlh wrote:


It doesn't work. If I duplicate the entire workbook, there will be no links to break as they are all from the same workbook. However, if I delete the sheets I do not want, the referenced data will have #REF! error.


My suggestion was badly worded. Instead of "first break the links you need to break" I should have written "first convert formals referencing to the sheets you are going to delete to values".


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Select multiple sheets in Excel using Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.