New Command Buttons

skull_eagle

Board Regular
Joined
Mar 25, 2011
Messages
89
Hi,

I'm struggling with this one.

I'm adding new command buttons to my userform based on a search. I don't know how many command buttons will be created each time.

I need to identify which button the user is clicking so I can use that button name as a variable.

VBA Code:
Set NewBt = SearchForm.Controls.Add("Forms.CommandButton.1", cl, True)
With NewBt
    .Top = 70 + (sCount * 22)
    .Left = 472
    .Height = 18
    .Width = 18
    .Visible = True
    .Font.Size = 11
    .Caption = "="
End With
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Read the posts and solutions for dynamically added controls, for example
User form with dynamically created CheckBoxes

You will need add your buttons to a collection as you create them.
You will need to create a class that handles events for your buttons (also part of your collections)
- this class will sense your button events.
If you want your form that is hosting the buttons to receive the event notifications you will need to create another class

there are several examples on the MrExcel Message Board that provide examples on how to do this.
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,040
Members
449,092
Latest member
ikke

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