Reputation: 60751
Although the following background information is not so relevant to the question, I am including it in case you are curious:
I am running:
xlWorkBook.RefreshAll();
on an Excel workbook, and sometimes I get this message:
Using c# .NET 3.5 I would like to get rid of this pop up immediately after detecting it.
How can I programmatically detect it and close it / press OK?
Please note that I want to be able to identify this pop up even if it is in the background!
Upvotes: 0
Views: 803
Reputation: 1592
You can use Application.DisplayAlerts = False
to suppress alert/popups. However, that should ideally not be correct behaviour. When we call RefreshAll()
and an error popup is displayed, the excel does not refresh the data. It would still show the old data.
For solving this, you can keep Application.DisplayAlerts=True
and create two threads: one would open excel application & call RefreshAll() and other would wait for specified time (say 20 mins). If the 1st thread did not return back in 20 mins (likely due to popup), the 2nd thread would kill excel process. The 1st thread will get released and it will log exception that the file is not refreshed.
Upvotes: 0
Reputation: 5234
You should be able to set display alerts to false and avoid these
Application.DisplayAlerts = False
Upvotes: 4