VBA: Events for several dynamically added buttons - vba

I am adding several CommandButtons dynamically to my user form. To assign code, I used the answer of this question: Assign code to a button created dynamically
However, I need to determine which button has been clicked. They all do have different names. Therefore, my initial idea was to get the name of the clicked button in the CmdEvents_Click() procedure. However, I have not found a solution how to do that.
Does anyone have a solution how to trigger button specific events?

Add the Name of the new command e.g. like ctl_Command.Name = "name_" & i
Then in the CmdEvents_Click just use CmdEvents.Name.

Related

Dynamically Add Option Buttons to Excel UserFrm with One Event Handler

I have a custom user form in Excel where the number of option buttons is dynamic, depending on what a user selects from a combo box. I have written a script that will add and format those option buttons with appropriate captions, groupname, etc. However, I would like it so that after those buttons are added dynamically, if a user clicks a button from a group just added, then more code will be executed. I am aware that one can create a custom class so that multiple userform controls are handled with one event handler, but I can't figure out how to get this to work with controls that were added dynamically to a form, after the form initialized. I am hoping this question makes sense. Thanks in advance for any help you can offer.

Excel vba - command depending on previous command

Firstly I am new to vba, and in the course of learning have learned a ton from searching this site. Unfortunately this time no success.
I do not know how to tackle this.
My "home" userform has 6 command buttons with no caption to them (empty).
On pressing any one of these, a "names" userform is opened, with 10 command buttons - each is captioned with a different persons name.
I want the chosen perdons name assigned to the caption of the command button that triggered "names" to appear.
On each form I have placed a label. This label's caption changes to the caption of tge command button clicked.
Options I have considered:
1. Multiple multiple IF statements
2. Assigning variables - cant figure out what to assign
I can post my code, but as i do not know where to begin I don't think it would be to much use.
Managed to figure it out!
Made a module with if statments.
Called it from "names" every time a name is chosen.
By doing this no need for writing the same code over again.

Changing ActiveX Component Name Properties Dynamically in Word

I am trying to develop a dynamic user form in a Word document that will create an ActiveX radio button with a generic name and then rename that created radio button to make it have a specific number based on its location in the form.
So far I believe I have all the components to write the code because I am able to create the button. I create the button by using VBA to import a quick part that has the radio button with a defined radioButtonX name and I am able to change the name property of that radio button to radioButton1 for example. The problem that I am running into is that my code will insert the quick part with the generic radioButtonX name and then fail to change the radio button name because it says that radioButtonX does not exist. However, I can manually run the second part of the code after radioButtonX has been inserted and I am able to successfully change the radio button name giving me the end result that I am looking for in two separate steps.
I am a self taught VBA scripter for the last year so I am far from an expert at coding. A few of the strategies that I have taken so far were to:
Put in waits (thinking that pausing the script would give the script time to recognize the new radio button)
Separated the code into different subs having one sub create the radio button and then call a sub to change the name (hoping this would update VBA)
Separated the code into different modules having one modules create the radio button and then call a modules to change the name (hoping this would update VBA)
I was hoping for some advice, strategies, or sample codes that I can use to get VBA to recognize the new radio button that I have inserted while the code was running. Another thought that I had was maybe there is a command that exists that will have VBA refresh its knowledge of variables, but I have not have any luck finding something like that in my web searches to this point.
I tried to simplify the code that I was working on and pull out the code that would perform the function that I was requesting. Running the simpler code was successful and listed below.
Private Sub AddRadioButton()
Selection.TypeText Text:="TestRadioButton"
Selection.Range.InsertAutoText
ActiveWindow.View.ShowXMLMarkup = wdToggle
ChangeButtonName
End Sub
Private Sub ChangeButtonName()
ThisDocument.radioButtonX.Name = "radioButton1"
End Sub
For this script to work you must create a quick part or a radio button that is named TestRadioButton. I think now the root issue has to deal with timing that looked like it wasn't working because the script that this code came from is using a quick part with multiple generic radio buttons in it so the script executing does not recognize the new radio buttons while running.

PassBook + ios 6

In Pass.Json file, how to write a code for adding button and how to add hyperlink text, which dynamically update the link, after user click the hyperlink text?
Please let me know if someone come across with same requirement.
You cannot add a button or hyperlink to a pass.
There is a fairly clumsy workaround to update a pass based off a user action that takes advantage of the fact the URLs, phone numbers, dates and addresses that appear on the back of the pass are automatically made clickable.
So while you cannot add a button or hyperlink text per-se, you could add a link to a script that when clicked on, triggers a push update that updates the pass with your new content. This pass contains a good example, and the source code is available here.

How to use Mouseout Function in VBA with a condition Check?

Hi I have a VBA application with a combobox selection option.One of the combobox option is Other which when user select that option an invisibled label will pops up and prompt the user to fill the txtOther control.now my question is how I can get rid of the prompted label and make it to invisible after user fill the txtOther and move(focused)in other control?
here is a shot of my app:
Thanks for your time and help
It depends on how often or when you want the check to be done. I couldn't find a good reference to show you all of this, but you can view your VBE.
Within the code behind your userform you can use events for the text box.
If you want the check done every time you leave the text box:
Use the TextBox_Exit event.
If you want it to fire whenever the contents are changed, used TextBox_Change. There's lots of options, but based on your explanation I'd probably use Exit.
This answer shows some syntax examples for using the Textbox_Exit event.