I am trying to edit macro enabled Excel file using c#.
I have done with the editing and need to validate all that data using already defined macro [VBA - Button]. I am able to run macro using code mentioned below:
workbook.Application.Run("Sheet1.validate_Click");
Now, the problem is, whenever the macro is called that will validate the data which I had inserted in Excel sheet and give the output shown below:
Now I need to click on Yes Button Programmatically. which will ask to save that file which will be automatically created by that Validate Button.
Here I am stuck, that how could I programmatically click on Yes Button of Alert Dialog that appears.
Please Help me, I am without clues here, I googled a lot but could find nothing which serves my purpose.
As @Tom mentioned in the comments, the real solution would be to change the VBA code. But since this isn't an option that's available to you, you'll have to use some sort of hackish work-around. I haven't done much testing, but I'd assume that your COM Interop calls are also blocking because of the modal dialog.
About the only way I've come up with to handle dialogs generated by VBA from managed code is to use win32 functions to poll for the target window, then send a simulated mouse click when it's found. This is the class I use:
Calling code: