0
votes

I am using a userform and have issue with the "unload me"

If I place the "unload me" before my private sub => the private sub doesn t start

If I place it after, I cannot click in the cell of the new workbook (which is what I see first on my screen when the macro is done)

Where should I put the unload me to make it work properly?

Code below:

Private Sub CommandButton3_click()

        Private_Sub

Unload Me

End Sub

Private Sub Private_Sub()

    Workbooks.Open Filename:="U:\mydocuments\Workbook.xlsx"

End Sub

Please tell me if I don t make myself clear enough.

1
On what part of the code did you opened the userform? - kulapo
It s on another module (in personal Macro), and is only a sub with "My_userform.Show" inside - Pierre44
You should never use Unload Me, you should use Me.hide rubberduckvba.wordpress.com/2017/10/25/userform1-show - Storax
Using Me.hide instead doesn t solve the problem if I put it at the end (I still don t understand why), but it does work if I leave it at the beginning. - Pierre44
Me.hide works for me - Storax

1 Answers

0
votes

The following code in a userform works

Option Explicit

Private Sub CommandButton3_Click()
    Private_Sub
'    If MsgBox("Hide form?", vbYesNo, "Test") Then
        Hide
'    End If
End Sub


Private Sub Private_Sub()
    Workbooks.Open Filename:="...Filename..."
End Sub

In order to test it put the following code in a genral module

Option Explicit

Sub frmTest()

    Dim frm As UserForm1

    Set frm = New UserForm1
    frm.Show
    Unload frm

End Sub