2

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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Mac471
  • 423
  • 5
  • 16

4 Answers4

3

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

tell application "/Applications/Microsoft Office 2011/Microsoft Excel.app"
    open theWorkbookFile
end tell
jackjr300
  • 7,111
  • 2
  • 15
  • 25
0

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

Nick Groeneveld
  • 895
  • 6
  • 18
  • I tried this too - it also opens Windows Excel under Parallels. Hope this question helps save others a lot of frustration. – Mac471 Jun 13 '15 at 14:55
  • Thanks for your edits. Microsoft Excel is the default editor for xlsx files (alternative 2) and it was still opening Windows Excel/Windows 8.1 under Parallels. It looks like specifying the path to the application (alternative 1) similar to the answer by jackjr300 above seems to be the best way to go. Thanks. – Mac471 Jun 15 '15 at 15:14
0

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
Frank C.
  • 7,758
  • 4
  • 35
  • 45
  • I tried this to answer your question - it still opens Windows Excel under Parallels so perhaps it does carry the same ID. – Mac471 Jun 13 '15 at 14:53
  • Thanks for evaluating. While I have Windows (VMFusion) I don't have excel installed there so I couldn't get the information. – Frank C. Jun 14 '15 at 13:10
0

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