vba to change name of multiple UserForm CommandButtons

novabond

New Member
Joined
Mar 26, 2022
Messages
36
Office Version
  1. 365
Platform
  1. Windows
hello.
(i dont write code but, can tweak obvious referencies within code.....)
I have been looking online most of today but, I cant find existing code, which i can modify to do something like this:

1)
let say the set up is:
in worksheet "CommandButton Names"
i have a list A1:D20 containing info to change CoomandButton (Name) -
A1:A20 = within Userform (Name)
B1:B20 = from current CommandButton (Name)
C1:C20 = to new CommandButton (Name)
D1:D20 = and new CommandButton Caption (caption change is a bonus, it isnt crucial if complicates things)

e.g.
ABCD
1within Userform (Name)current CommandButton (Name)new CommandButton (Name)new CommandButton Caption
2UserForm_BCommandButton_A_1CommandButton_B_1Caption_B_1
3UserForm_BCommandButton_A_2CommandButton_B_2
4UserForm_CCommandButton_A_1CommandButton_C_1
Caption_C_1​

iit would be ok to do one new userform at a time too, if that makes sense... or any other way you know that will achieve the outcome I want of auto renaming UserForm CommandButtons...

2)
It would also be great, if there was a macro that could export the details of the UserForm CommandButtons too, that would be really useful but, not important...

TIA!....
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Here is an example of a simple for and code that changes captions when the UserForm initializes

Book1
ABCDE
1FormControlCaption
2UserForm1CommandButton1Button 1
3UserForm1Admin
4
Sheet1


VBA Code:
Private Sub UserForm_Initialize()
   Me.Caption = Range("C3")
  CommandButton1.Caption = Range("C2")
End Sub

I added a button on the worksheet to show the form (which runs the UserForm1_Initialize Sub).
1693068690308.png


You really do not and cannot change your control names dynamically. You event handlers (like the Click) event for your controls are named from the Name of each control.
I you change the control names dyamically (I do not think you can do this at run time), it would render your event handler code useless.

So, you can change Captions, but you cannot change Names.

Dynamically changing captions would be very useful in a multilingual environment.

Labels, Buttons, Forms, OptionButtons, CheckBoxes, ... have Captions that could be changed this way.
Also, messages in MsgBoxes.

I hope this helps.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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