eventhandling of dynamically created textboxes

Don Juan Matus

New Member
Joined
Mar 13, 2019
Messages
1
Hello,

In fact I need a list of inputboxes:
- first collumn is with fixed numbering
- second and third collumn should behave like inputboxes for values
- I need 20 rows of it

As the listbox-control doesn't allow user input, I thought of creating
the textboxes dynamically in code and assign them to an array.
The following works - despite that no program break is possible there:

Public controlarry(20, 3) As Object

Sub createTxtBoxexs()
dim i%

for i = 1 to 20
Set controlarry(i) = Worksheets("xyz").OLEObjects.Add("Forms.TextBox.1")
end sub

It is sayed, that I need a class and have to use WithEvents.
But the following is a syntax error:
public withevents txtEvents as Forms.TextBox

How can I process the events of the created TextBoxes?
Can you please give an example for it?
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,503
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Welcome to the forum.

It's MSForms.Textbox, not Forms.Textbox.

In my opinion it would be simpler to use one set of textboxes and have them add data to the listbox, but if you want multiple rows there are numerous examples on the forum of how to use classes and withevents.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,108,992
Messages
5,526,109
Members
409,685
Latest member
Bellybb

This Week's Hot Topics

Top