1

Is there a way for Applescript to open an Excel workbook (.xls) that is password protected?

I see that in the library there are functions to check if a workbook has password, but I do not know the proper syntax for opening a wb with password protection.

Tell application "Microsoft Excel"
  -- set theWb to path of .... etc.
  open theWb with password "abc" ? <--- what should go here?
end tell
1

There is a way to open a Excel workbook (xlsx, in my example) which is protected either the workbook and/or the sheet. You can use the following script:

set passwd to "1234" -- whatever you want
set theWbpath to "/Users/xxxxx/Desktop/number1.xlsx" -- example path
set theWb to "number1.xlsx" -- example file
set theSheet to "sheet1" -- example name of sheet
tell application "Microsoft Excel"
    open theWbpath                
    unprotect workbook theWb ¬ --> 
        password passwd        --> workbook part, can be left out
    unprotect sheet theSheet ¬ --> 
        password passwd        --> sheet part, can be left out
end tell
8
  • I don't know what the sign ¬ means in the AppleScript context so you may have to revise the formatting – klanomath Jun 17 '16 at 14:55
  • 1
    @klanomath, ¬ is: The Continuation Character – user3439894 Jun 17 '16 at 17:40
  • tell application "Microsoft Excel" open "Macintosh HD:Users:user:Desktop:fileName.xls" it stops at this point, and doesn't continue to do the next line of code which is unprotect workbook theWb – klutznic Jun 21 '16 at 2:34
  • does it only work for xlsx files? – klutznic Jun 21 '16 at 3:08
  • It could be related to the Excel version you use; I tested it with v.15 (actual v). What do you use? I could try it with different Excel versions on some other Macs. – roadrunner Jun 21 '16 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .