Close userform without clicking a button

dimitri

Board Regular
Joined
Nov 8, 2010
Messages
78
Hi,
I have a userform with a button that says "Save Changes" with code attached to it. when the user hits the "Save Changes" button, I want a box to briefly appear saying "Your changes have been saved".

Currently, I have that box as a userform. I'm having trouble getting the box to close automatically. I tried putting the application.wait code in the initialization section of the userform followed by Unload Me, but I get an error.

Any help would be appreciated.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try in the userform's code module

Code:
Private Sub UserForm_Activate()
Application.OnTime Now() + TimeSerial(0, 0, 3), "CloseUserForm"
End Sub
and in a regular module

Code:
Sub CloseUserForm()
UserForm1.Hide
Unload UserForm1
End Sub
 
Upvote 0
I tried the first code but the user form doesn't go away automatically. I moved my original code from the "initialize" section to the "activate" section of the userform's code modual and it works the way I want it to.

Code:
Private Sub UserForm_Activate()
Application.Wait Now + TimeValue("00:00:02")
Unload Me
End Sub

I didn't know about the "Activate" section of the module. what differeciates it from "Initialize"?
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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