Dynamic userform multipage command buttons

cutelittleguy

New Member
Joined
Dec 9, 2016
Messages
1
I created a userform that automatically adds pages and labels and textboxes and command buttons in a multipage. I now when click on any of the comman buttons on a page, it does nothing. I am novice in van macros and need help...
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
20,890
Office Version
  1. 365
Platform
  1. Windows
For a control that has been added at runtime to respond to events, one has to declare the variable with the keyword WithEvents. Here's an example...

Code:
[COLOR=darkblue]Dim[/COLOR] [COLOR=darkblue]WithEvents[/COLOR] NewButton [COLOR=darkblue]As[/COLOR] MSForms.CommandButton

[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] UserForm_Initialize()

[COLOR=green]'   Add new button[/COLOR]
    [COLOR=darkblue]Set[/COLOR] NewButton = UserForm1.Controls.Add("Forms.CommandButton.1")
    [COLOR=darkblue]With[/COLOR] NewButton
        .Caption = "MyButton"
        [COLOR=green]'etc.[/COLOR]
        '
        [COLOR=green]'[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]

[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] NewButton_Click()
    [COLOR=green]'etc.[/COLOR]
    '
    [COLOR=green]'[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Does this help?
 
Upvote 0

Forum statistics

Threads
1,190,656
Messages
5,982,133
Members
439,757
Latest member
85Sarah2005

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
Top