Create a command button with code

kotzo

Board Regular
Joined
Aug 1, 2010
Messages
119
Hi,

Is it possible to create a command button with code (during the macro execution) ?

I want the following thing:

After pressing a command button in my user form,
another command button should be created (or revealed)
on the same user form.

Thanks in advance,

Kotzo
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
could always have the visible setting to false then make it true in the code. otherwise something like:

Dim button As MSForms.commandbutton

Set button = Me.Controls.Add("Forms.commandbutton.1")
With button
.Top = dsa
.Left = asd
.Height = 25
.Width = 1
.Caption = ""
.BackColor = &H0&
End With
 
Upvote 0
Using the Visible property, something like

Code:
Private Sub UserForm_Initialize()
    Me.CommandButton2.Visible = False
End Sub
 
Private Sub CommandButton1_Click()
    UserForm1.CommandButton2.Visible = True
End Sub

HTH

M.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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