mark hansen
Well-known Member
- Joined
- Mar 6, 2006
- Messages
- 534
- Office Version
- 2016
- Platform
- Windows
This is probably a silly question... But is there an event so when you click on a button, it takes information from the button (any button) and runs code. I have a user form with 80 buttons, and I have the same code on each Private sub CommandButtonX_Click() event … Except for the button number.
I was wondering if I could have something like … When a button is clicked... Take the caption from that button and activate that sheet and check to see if I need to close the user form. I see there is a mouse down and up events, but haven't used them...
When this user form is run, it takes the worksheet names and puts them on buttons, makes the user form Modeless so it just sits on top of the sheet while you work. (in a small display), When you click in the user form, it opens and displays buttons for each worksheet, allowing you to jump to a different worksheet. Its designed to be floating Table of Contents when you have many worksheets. Except for the .show command line, its completely self contained.
As I have (mostly) identical code for each buttons (up to 80), I have the above code replicated for each command button click event.
I'm just trying to make sure there isn't an easier way to set this up.
Thanks for any insight,
Mark
VBA Code:
Private Sub CommandButton78_Click()
Dim Str As String
Str = Me.CommandButton78.Caption
Worksheets(Str).Activate
If cbkAutoClose Then Call Label1_Click
End Sub
I was wondering if I could have something like … When a button is clicked... Take the caption from that button and activate that sheet and check to see if I need to close the user form. I see there is a mouse down and up events, but haven't used them...
When this user form is run, it takes the worksheet names and puts them on buttons, makes the user form Modeless so it just sits on top of the sheet while you work. (in a small display), When you click in the user form, it opens and displays buttons for each worksheet, allowing you to jump to a different worksheet. Its designed to be floating Table of Contents when you have many worksheets. Except for the .show command line, its completely self contained.
As I have (mostly) identical code for each buttons (up to 80), I have the above code replicated for each command button click event.
I'm just trying to make sure there isn't an easier way to set this up.
Thanks for any insight,
Mark