Close All Open Dialogs

Good day,

What I’m trying to achieve is to close any open dialogs on the screen during the process. Should the robot encounter an issue, I want to close all the open dialogs and start again from fresh. The problem being I cannot know for sure what dialogs are left open. So I want close any open, leaving the main application running.

I was trying something like:

For each myForm as Form in My.Application.OpenForms

But the Invoke code does not like this. Anybody have an suggestions?



1 Like

I’ve managed to get the Invoke Code to accept my code but on execution I get the following error

Message: No compiled code to run
error BC30002: Type ‘System.Windows.Forms.Form’ is not defined. At line 1
error BC30002: Type ‘System.Windows.Forms.FormCollection’ is not defined. At line 2

My code reads as follows:

Dim OpenForm As System.Windows.Forms.Form
Dim OpenForms As System.Windows.Forms.FormCollection

For Each OpenForm In OpenForms

Hope someone out there can help