Use same button that opens userform to close userform

SantanaKRE8s

Board Regular
Joined
Jul 11, 2023
Messages
121
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
@SantanaKRE8s
I hope that when you are looking for a solution that you won't happen to see what you wrote (Cannot share code)
That does not help anybody that is looking for a solution.

@MY Answer Is This & Micron
Slight modification.
Code:
Sub My_Answer_Is_This()
Select Case True
    Case QuickView.Visible: Unload QuickView
    Case Else: QuickView.Show vbModeless
End Select
End Sub
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
The code I used should have worked if you had modified the userform name
But maybe you did not think to do that:
Here is a script with the proper userform name.

VBA Code:
Sub RectangleRoundedCorners1_Click()
Select Case QUIKview.Visible
    Case True: Unload QUIKview
    Case False: QUIKview.Show modeless
End Select
End Sub
 
Upvote 0
@SantanaKRE8s
I hope that when you are looking for a solution that you won't happen to see what you wrote (Cannot share code)
That does not help anybody that is looking for a solution.

@MY Answer Is This & Micron
Slight modification.
Code:
Sub My_Answer_Is_This()
Select Case True
    Case QuickView.Visible: Unload QuickView
    Case Else: QuickView.Show vbModeless
End Select
End Sub
Thanks for showing user this I just assumed user would understand to modify this:
 
Upvote 0
I guess I'm just lazy sometimes I never give my Userforms special names.
I just use the default name given.
 
Upvote 0
@SantanaKRE8s
I hope that when you are looking for a solution that you won't happen to see what you wrote (Cannot share code)
That does not help anybody that is looking for a solution.

@MY Answer Is This & Micron
Slight modification.
Code:
Sub My_Answer_Is_This()
Select Case True
    Case QuickView.Visible: Unload QuickView
    Case Else: QuickView.Show vbModeless
End Select
End Sub
You are right the code is in this solution which is why I marked this one as the solution. Sorry backed up on a lot of work. So I will make the corrections as they are brought to my attention.
 
Upvote 0
You've got about half a dozen or more working solutions suggested so you can have different one for each day of the week while still having some spares.
Good luck and thanks for letting us know that you have working solution to your problem.
 
Upvote 0
Code from post 62 presents an error for me and highlights Case QuickView.Visible

1691603614630.png
 
Upvote 0
Probably. I spelled it the way the form is named. Yours is not and I missed that. Sorry.
FWIW, it's "QUIKview" in the file.
 
Upvote 0
Thanks for all the help from both, and the feedback that will help my next post to be easier to understand what Im trying to do and get a solution. Its working perfect now. And is shared with my team.
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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