AppleScript to copy cell range to clipboard as image is broken after Office Excel update 16.11

applescriptms office

I have a simple script that opens an excel file and copy the used range to cilpboard as image. It was working for at least 5 years. Now with the latest update from microsoft it is not longer working and throwing parameter error (-50). I have tried all combinations of optional parameters with appearance and screen. No matter what I try I always get this parameter error. Please suggest how can I change the parameters to make it working or confirm that it is not working for you too and hence a bug that should be reported to Microsoft. I have following code. The excel file is opened but then I get error -50 stating Parameter error. Parameter 'used range' is correct according to MS Excel dictionary documentation and the script works with Microsoft Excel 16.10.

    set filepath to "/Users/ayesha/Documents/ayesha/test.xlsx"  

    set scriptFilePath to POSIX file filepath

    tell application "Microsoft Excel"

        launch

        set myworkbook to open workbook workbook file name scriptFilePath

        copy picture used range of active sheet     

    end tell

Best Answer

Any script and file that you don't change and that works on Excel 16.10 (or Excel 15.41 from before the code base was changed / unified in version 16) and then breaks is a regression bug you should file with Microsoft. Version 16.10 has about 20 bugs we're taking with Microsoft and not all of them are fixed in Version 16.11 - some of the bugs are so bad that the ~/Library and container files become corrupt and the application itself will not even launch in Finder.

Full stop - file a bug with them after you have exhausted their support channels. Support is getting some pretty decent workarounds for some bugs, but version 15 to version 16 was a massive change so there clearly were (and today are still) tons of regressions.

In that bug you need to tell them (and us) what license you are using. The same excel program works differently based on how you license it. Features turn on and off so you don't have the same behavior based on licensing.

Now - I did try to dig into the Dictionary and see if I can find an error in your usage above, but your code is correct as the calls are documented. The problem is Excel - not your script.

I don't like loading older software - so the first thing I would do is try opening your file in Numbers and scripting there until the Excel version 16.xx works out all the kinks.

If you wanted to go back - here's the 15.41 installer - but you will need to consider cleaning everything potentially like Outlook identities, caches, preferences, etc... or installing this older Office on a new Mac OS or VM with a clean install or make a new user so you don't have old preferences that are from a newer version of the tool.