It would help if you could upload your current macro and provide more details about your workflow (for example, the program you're working in, and what exactly it's doing that you want the macro to wait for) but if you're already using a user-defined variable to open and close this window, you should be able to have that opening and closing all take place in its own loop action (again, I can't advise which one without more details or the current version of the macro), which would ensure everything you need to wait for is done before the macro proceeds.