Error in Excel to End Macro and Show Fail Message in Text Box

Hello!

I was wondering if anyone had an AppleScript or macro sample for aborting a macro if an error occurs within an Excel sheet.

Example - Cell A is a drop down with 5 options. If I enter text that is not within that list of 5, I get the error below. I would like the macro to abort when this appears.

Screenshot 2023-03-15 at 7.18.08 PM

After inserting the text, add a short Pause (to allow time for the alert to appear), and then use the Found Image condition to determine if the error is on the screen.

If you don't want to use image detection, notice that many Excel menu items are disabled when that alert is up -- and KM has a "Menu" Condition. So if you've got a cell that only allows numbers between 1 and 5, make it active then run this macro (change the number in the first action to see the different behaviours):

Excel Alert Detector.kmmacros (3.9 KB)

Image

Thank you for the response @Nige_S ,

I used 1 - 6 as an example here.. it's more like 20 different options that are all strings of words in a drop down using data validation. And then if the string is not exact when the user inputs, the error appears. This would still work right? I think it should from the "If condition" on. Giving it a shot now.

Thank you!