VBA UserForm Unload Me or Cancel Button causes conflict with minimizing CorelDRAW window

I wanted to post this in the developers section, I'm probably blind but I couldn't figure how to create a post over there, if this is the wrong place for a VBA question I apologize in advance.

I got the 2024 Humble Bundle CorelDRAW Graphics Suite version and I'm currently discovering VBA. I'm trying to build my first user interface or User Form for a macro, the code for the form currently looks like this:

Option Explicit Private Sub cbVisibleLayersOnly_Click() End Sub Private Sub cmdCancel_Click() ' Close exportToForm Unload Me ' Unload exportToForm End Sub Private Sub UserForm_Click() ' Loads the User Interface exportToForm.Show vbModeless End Sub

I run the code by putting the cursor in the UserForm code and hitting F5, the focus switches over to CorelDRAW, a window appears with a checkbox and a command button which reads "Cancel". If I click the "Cancel" command button or the X in the top right corner of the window (doesn't matter which of the two I use) the window closes as expected and I can minimize CorelDRAW just fine.

If I repeat these steps once or a couple of times and maybe switch from the editor to CorelDRAW as main window and back to the editor, eventually it doesn't switch focus to CorelDRAW but instead opens the UserForm on top of the VBA editor. Once that happens the "Cancel" or the X button often doesn't close the UserForm window anymore so I have to stop the code by hitting the blue square on the top or pushing STRG + BREAK. At that point If I switch focus by hand to CorelDRAW and attempt to minimize it it behaves buggy, the window will minimize for a brief moment so the editor becomes visible but immediately brings CorelDRAW back into focus/Maximize or the CorelDRAW window will shrink to a very small bar on the top left of the screen instead of the task bar and if I single click that bar it goes back to maximize/main focus.

Sometimes I also get the error code: Run-Time error '401': Can't show non-modal form when modal form is displayed

Once it behaves like that I have to close both the editor and CorelDRAW and reopen it to get back to normal behaviour.

There isn't much "linking" yet between the UserForm code and the module code sofar, I suspect the error is somewhere in the sparse UserForm code but I can add the module code if necessary.

  •  - your post has been moved to the Developer Area > CorelDRAW and Corel DESIGNER API forum. This is the forum for discussing questions related to the programming interface(s) in CorelDRAW.

  • Halp, 

    You are seeing the error message because you have a Click event on the UserForm

    UserForm_Click

    This then tries to show the form again which you already have open.

    I would suggest you look at the FileConverer for for a good example of how to create a Module and add a Sub that then opens a Form. Also do not make that Sub private, because you want it available to the UI so that you can add a button in the CorelDRAW UI to call it, or you can use the Scripts Docker.

    -Shelby