0

How can I use Applescript to open an Excel file in MacOs and enable the macros?

I have tried :

-- Set the path to your Excel file
set excelFile to "/Users/spagcoder/Desktop/proms webform/PROMS.xlsm"

-- Launch Excel in the background
tell application "Microsoft Excel"
    activate
    delay 5
    open workbook workbook file name excelFile
    delay 3
end tell

tell application "System Events"
    tell process "Microsoft Excel"
    click button "Enable Macros" of window 1
    end tell
end tell

This opens the file and the but then the script just hangs when the disable/enable macros alert comes up.

If the file is already open and the macros dialog box is open, I can run a script that is just

tell application "System Events"
    tell process "Microsoft Excel"
    click button "Enable Macros" of window 1
    end tell
end tell

And this works. The button gets clicked.

SpagCoder
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 30 '23 at 21:51
  • I want the script open an Excel file (on Mac OS), automatically enable macros and then run a macro. When I run the script, it opens the Excel file and Excel immediately pops up a dialog asking me to enable or disable macros. The script won't proceed until I click on one of the buttons. This means that it never gets to the part of the script that clicks the button programatically. – SpagCoder Aug 01 '23 at 08:03

0 Answers0