Hello
Small problem on one of my macros.
I have a userform that pops up and asks you to make a face or edge selection.
The macro code hand:
UserFormSelectFace.Show vbModeless
CoincidentsCtresWindows "SOLIDWORKS", UserFormSelectFace.Caption, True
As long as the selection is not made, the macro continues. On that side no worries
The problem comes from the cancel button, because if you press it you exit the userform but the continuous macro and bugs (because no selection is made)
I tried to put this in the userform:
Private Sub BoutonCancel_Click()
Msgbox "TEST"
End
End Sub
But when you press the cancel cross, same result as before (no msgbox " TEST " and the macro continues and bugs.)
Any idea about the reason for this failure? I don't understand how to trigger an event with this cancel button.
Hello
I'm surprised normally if there is no hide function of the userform, pressing the cancel button should go through the msgbox and leave the form displayed.
On the other hand, when you say that the macro continues, what exactly does it do with the form displayed? Maybe it comes from there
@Cyril.f I also have a
Unload UserFormSelectFace
a little bit below in my code, once the selection is checked. I had forgotten that one!
On the other hand, adding this in the userform, it seems to do the job:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
MsgBox "Macro interrompue"
End
End If
' If CloseMode = vbFormControlMenu Then Cancel = 1
End Sub
The QueryClose is the press on the cross (you can even inhibit the closure to force you to go through the Ok and Cancel buttons).
Yes, that's what I saw with the code I got back.
I commented on the line:
If CloseMode = vbFormControlMenu Then Cancel = 1
Which effectively inhibited the cancel button.
And then I changed it to put my warning message and the end.
From what I understand the BoutonCancel_Click() does not work in excel (unlike Excel)
It must be in SW unlike Excel
For SW you need a form button that cancels and adds a processing.
Yes, that's right, in SW unlike Excel!
The problem is that some people pressed this cross to exit the macro and that the code did not interrupt, and went into debug mode following one or more errors, so he called me on the phone to find out why!
Now this should solve my problem!
1 Like