AppleScript Tell Application Microsoft Excel Opens Windows Excel on Mac with Parallels?

1.8k views Asked by At

I am trying to use AppleScript to manipulate Mac Excel 2011 files on a Macbook Air running OSX Mavericks. I also have Parallels installed with Windows 8.1 and Windows Excel 2013.

When I run the following test script, it starts up Parallels, Windows 8.1 and Windows Excel 2013 instead of Mac Excel 2011. It doesn't even do this consistently - sometimes it will open Mac Excel 2011 after prompting for a file.

Here's the simple test script:

set theWorkbookFile to choose file with prompt "Please select an Excel   workbook file:"
set theWorkbookName to name of (info for theWorkbookFile)

tell application "Microsoft Excel"
    open theWorkbookFile

end tell

I tried replacing "Microsoft Excel" with "Mac Excel" but the compiler keeps changing it back.

Am I missing something simple here?

4

There are 4 answers

2
jackjr300 On BEST ANSWER

You can use the path of the application, like this :

tell application "/Applications/Microsoft Office 2011/Microsoft Excel.app"
    open theWorkbookFile
end tell
2
Frank C. On

You could open it with it's ID, however not sure if the Windows version carries the same generic, for example:

set exID to get id of application "Microsoft Excel"
tell application id exID
   make new document
end tell
2
Nick Groeneveld On

You could try to run the application from inside a tell application "Finder", like this:

tell application "Finder"
    tell application "Microsoft Excel"

        -- Your code

    end tell
end tell

EDIT

It might be something else, outside of Applescript. I've tried two alternatives.

  1. Use a 'hard path', like so:

    set pathToExcel to "Macintosh HD:Applications:Microsoft Office 2011:Microsoft Excel.app"
    
    tell application pathToExcel
    
        -- Your code
    
    end tell
    
  2. Make sure the default editor for excel-files is the correct program, like shown here:

enter image description here

0
David Cox On

In order to script the more complex actions in Excel, I needed to get rid of the "Windows" application that was launching (the work around of trying to use the path to my '"Mac" application was not good for complex commands). To get rid of the "Windows" version I launched "Microsoft Excel" with an apple script. I brought up the contextual menu for the item that launched in the dock, and selected "Show in Finder" from he Options item. I then quit the item that had launched, and put it in the trash. The location of these "apps" seem to change from version to version of Parallels.

I also added the following bit to the top of my complex script. I don't know if the path will remain consistent or not, but in case it does, this gives me a chance to fix the issue before my script starts:

tell application "Finder" if exists POSIX file "/Users/davidacox/Applications (Parallels)/{56aed35f-dfb1-41ea-8ade-aebd86441327} Applications.localized/Microsoft Excel.app" then

    display dialog "The evil excel stub is back"
end if

end tell