Activating and closing a userform in a macro

mcmahak

Board Regular
Joined
Jun 2, 2003
Messages
54
I have a userform created with the info that I need. Now i just need to be able to open it with my Auto Open macro and then close it and save the data in the combobox to a particular cell when the ok button is clicked. Anyone have code for this. I tried searching and ddin't get any returns for this topic.

Thanks,
Kevin
 
OdinsDream said:
When you need to close the userform, try:

Unload Me

or...if you're not in the UserForm's own code section, try:

Unload UserFormName

I tried adding Unload (UserForm1) in the auto open program and I got an error "Cannot Load or Unload object"

Here is my code for the UserForm1, let me know if there is something wrong with that:

Code:
Private Sub CancelButton_Click()
    Do
        z = InputBox("Please enter password", "Enter Password")
        If (z = "dsp") Then Exit Do
    Loop While z = ""
    End
End Sub

Private Sub ComboBox1_DropButtonClick()
    Sheets("Sheet6").Select
    ComboBox1.RowSource = "A5:A50"
    Sheets("Sheet2").Select
End Sub
Private Sub OK_Click()
    Sheets("Sheet6").Select
    Range("A1") = Me.ComboBox1.Value
    Sheets("sheet2").Select
    Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = 0 Then
        End
    End If
End Sub

Thanks again,
Kevin
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,387
Messages
6,124,637
Members
449,177
Latest member
Sousanna Aristiadou

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top