Use same button that opens userform to close userform

SantanaKRE8s

Board Regular
Joined
Jul 11, 2023
Messages
131
Office Version
  1. 365
Platform
  1. Windows
I have a button that I created from an object and I use it to open my userform, is there a VBA code to use the same button that opens the userform to also close the userform, so that I dont have to add another button. I already have a lot of buttons want to avoid more. attached is an image
 

Attachments

  • Button to open and close.png
    Button to open and close.png
    80.5 KB · Views: 19
Copy and paste the code for your button click event. The picture of your project objects (3rd one) is of no help, unfortunately.
Please paste your code between vba code tags (use vba button on posting toolbar to get code tags).

Or perhaps upload your file to a file sharing site.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
No, most likely Im doing it wron, I want to share the file. I think it would be easier.
 
Upvote 0
Did you change "UserForm1" in the code to the actual name you gave the userform?
It works like a dandy here.
 
Upvote 0
Did you change "UserForm1" in the code to the actual name you gave the userform?
It works like a dandy here.
I think Im not adding the codes in the correct place, I difrent codes in the sheet in the Userform in the modules so Im not sure where to put it. Which is why I wanted to share my Workbook.
 
Upvote 0
I changed the UserForm1 name to QuickView and it works like you want it to work.
Make sure to spell exactly as it should be. I spelled it different here then you do in your code.
Just goes in a regular module (Module1, Module2 or whatever regular module) where you always put your code to open a Userform
Code:
Sub This_Works_As_Advertised()
    If QuickView.Visible = True Then Unload QuickView Else QuickView.Show vbModeless
End Sub
 
Upvote 0
I changed the UserForm1 name to QuickView and it works like you want it to work.
Make sure to spell exactly as it should be. I spelled it different here then you do in your code.
Just goes in a regular module (Module1, Module2 or whatever regular module) where you always put your code to open a Userform
Code:
Sub This_Works_As_Advertised()
    If QuickView.Visible = True Then Unload QuickView Else QuickView.Show vbModeless
End Sub

I added the code in Module 6 It still opens but not closing, Also in Module 5 image below I have this other code, Im not sure if it could be causing the problem.


1691450901853.png



1691451032255.png
 
Upvote 0
The thing about the post 9 code is (I think) that the button caption remains the same. I think the other approach is more intuitive for a user in that the button implies one result will happen upon clicking, or it implies another because of the caption.
Micron, can I send it to you via email?
I guess so if you cannot post in a drop box or OneDrive instead. If you can send/receive private messages I can give you an address that I seldom use. PM me to let me know. The code I may write will become a post in this thread if you find it solves your issue.
 
Upvote 0
You should probably provide the code that is in the 'QUIKview' form. ;)
 
Upvote 0

Forum statistics

Threads
1,216,750
Messages
6,132,500
Members
449,730
Latest member
SeanHT

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