'win32com beating data validation

I am using win32com to:

  • open an instance of Excel,
  • change some cell values, and
  • save and close the instance of Excel.

Example:

xl = win32com.client.DispatchEx("Excel.Application")
wb = xl.Workbooks.Open(<enter file path here>)
ws = wb.Worksheets(<enter tab name here>)
ws.Range(<enter range name here>).Value = 2
wb.Close(True,<enter new file path here>)

My problem is that the relevant named range has a data validation which is being violated (in this instance != 2), but no error message is produced. What I would like is for the Python process to be interrupted, or even shut down as a result of the data validation violation.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source