In my VBA macros with non-modal userforms, it is often the case that I want to "hand control back to CorelDRAW" after the macro has done something. For example, if the macro has been used to create a selection, I want focus to go back to CorelDRAW so that the user can directly delete or otherwise work with that selection.
I have been doing this using AppActivate "CorelDRAW".
Most of the time, this works fine, but on occasion, this will generate a runtime error 5 - Invalid procedure call or argument.
Once this starts happening, it keeps happening - with any macro in which I do that, and with some macros written by others. I can't see their code, but I'm assuming that they are doing something similar to what I am.
Shutting down and restarting CorelDRAW does not fix this. If I log off of Windows, then log in again, everything is fine.
Any suggestions for how to avoid this problem with my VBA macros?
AppActivate has a second parameter wait. Have you tried using it?
I am not using the wait parameter.
Do you have any information that would lead you to think that using wait would help here?
If I use Application.ActiveWindow.Activate, then I seem to get the desired result.
Good idea? Bad idea?
No. I never used AppActivate. In my macro i used a couple of times API-s GetForegroundWindow / SetForegroundWindow
I think that non-modal userforms do not reset the ActiveWindow.Active flag to false.