I create Userform
'Sub Crt_UserForm(ByVal count23 As Long, ByVal Temp As String, shts As Variant)
Dim myForm As Object
Dim Textbox1 As MSForms.TextBox
Dim Textbox2 As MSForms.TextBox
Dim Label1 As MSForms.Label
Dim Label2 As MSForms.Label
Dim Button1 As MSForms.CommandButton
Dim Button2 As MSForms.CommandButton
'Dim shtchk() As MSForms.CheckBox
Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)
'Set myForm = CallByName(UserForms, "Add", VbMethod, "Test")
ReDim shtchk(count23) As MSForms.CheckBox
With myForm
.Properties("Name") = "Test" 'Иногда эта строка вызывает ошибку
.Properties("Caption") = "Выберите листы для защиты паролем"
.Properties("Width") = 300
.Properties("Height") = 150
End With
'For Each x In Me.UserForms
'If x.Name = "Test" & a Then
'Next x
Set Label1 = Test.Controls.Add("Forms.Label.1", "Label1")
Set Label2 = Test.Controls.Add("Forms.Label.1", "Label2")
Set Textbox1 = Test.Controls.Add("Forms.Textbox.1", "Textbox1")
Set Textbox2 = Test.Controls.Add("Forms.Textbox.1", "Textbox2")
Set Button1 = Test.Controls.Add("Forms.CommandButton.1", "Button1")
Set Button2 = Test.Controls.Add("Forms.CommandButton.1", "Button2")
With Label1
.Top = 10
.Left = 10
.Width = 50
.Height = 20
.Caption = "Текущий пароль"
End With
With Label2
.Top = 10
.Left = 70
.Width = 50
.Height = 20
.Caption = "Новый пароль"
End With
With Textbox1
.Top = 40
.Left = 10
.Width = 50
.Height = 20
'.Caption = "Новый пароль"
End With
With Textbox2
.Top = 40
.Left = 70
.Width = 50
.Height = 20
'.Caption = "Новый пароль"
End With
With Button1
.Top = 70
.Left = 10
.Width = 50
.Height = 20
'.Caption = "Новый пароль"
End With
With Button2
.Top = 70
.Left = 70
.Width = 50
.Height = 20
'.Caption = "Новый пароль"
End With
Test.Show
End Sub
'
after the actions are over, I delete the created userform:
Sub RemoveUserForm()
With ThisWorkbook.VBProject.VBComponents
.Remove .item("Test")
End With
End Sub
First time it runs OK. But when I run it second time, it gives the error "Ambiguous name detected: Test" in the string:
Set Label1 = Test.Controls.Add("Forms.Label.1", "Label1")
So, somewhere deleted object myForm with the name "Test" is stored and prevents from creating the Userform object with the same name. How to fix it?
The solvation was in method of call to userform object via .Designer property Set Label1 = myForm.Designer.Controls.Add("Forms.Label.1", "Label1")
and method of userform show VBA.UserForms.Add(s).Show
Sub Crt_UserForm()
Dim myForm As Object
Dim s As String
Dim Textbox1 As MSForms.TextBox
Dim Textbox2 As MSForms.TextBox
Dim Label1 As MSForms.Label
Dim Label2 As MSForms.Label
Dim Button1 As MSForms.CommandButton
Dim Button2 As MSForms.CommandButton
Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With myForm
.Properties("Caption") = "Smth"
.Properties("Width") = 300
.Properties("Height") = 150
End With
s = myForm.Name
Set Label1 = myForm.Designer.Controls.Add("Forms.Label.1", "Label1")
Set Label2 = myForm.Designer.Controls.Add("Forms.Label.1", "Label2")
Set Textbox1 = myForm.Designer.Controls.Add("Forms.Textbox.1", "Textbox1")
Set Textbox2 = myForm.Designer.Controls.Add("Forms.Textbox.1", "Textbox2")
Set Button1 = myForm.Designer.Controls.Add("Forms.CommandButton.1", "Button1")
Set Button2 = myForm.Designer.Controls.Add("Forms.CommandButton.1", "Button2")
With Label1
.Top = 10
.Left = 10
.Width = 50
.Height = 20
.Caption = "SMTH"
End With
With Label2
.Top = 10
.Left = 70
.Width = 50
.Height = 20
.Caption = "SMTH"
End With
With Textbox1
.Top = 40
.Left = 10
.Width = 50
.Height = 20
End With
With Textbox2
.Top = 40
.Left = 70
.Width = 50
.Height = 20
'.Caption = "SMTH"
End With
With Button1
.Top = 70
.Left = 10
.Width = 50
.Height = 20
.Caption = "OK"
End With
With Button2
.Top = 70
.Left = 70
.Width = 50
.Height = 20
.Caption = "SMTH"
End With
With myForm.CodeModule
x = .CountOfLines
.InsertLines x + 1, "Sub Button1_Click()"
.InsertLines x + 2, "MsgBox ""Hello!"""
.InsertLines x + 3, "Unload Me"
.InsertLines x + 5, "End Sub"
End With
VBA.UserForms.Add(s).Show
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=myForm
End Sub
Related
I want to create dynamic buttons and then implement the click method, but any help on the internet does not work here. I hope someone can help me here.
It is not possible to create all buttons. Unfortunately, there is no possibility to write in other languages because we can only use Excel and may.
This is about the infoBtn1_Click.
My Script
Option Explicit
Dim WithEvents infoBtn As MSForms.CommandButton
Dim WithEvents infoBtn1 As MSForms.CommandButton
Dim WithEvents frameCard As MSForms.frame
Dim WithEvents cardTitel As MSForms.Label
Dim WithEvents ausLabel As MSForms.Label
Dim WithEvents ausbilderLabel As MSForms.Label
Dim WithEvents amLabel As MSForms.Label
Dim WithEvents datumLabel As MSForms.Label
Dim WithEvents infoLabel As MSForms.Label
Dim add As Integer
Dim topPos As Integer
Dim ctl As Control
Dim n As Integer
Dim VorhabenArray() As Variant
Dim Free(1 To 5) As Long
Dim sh As Worksheet
Dim v As Range
Dim arr(0 To 40) As Integer
Dim i As Integer
Dim ausbildungNr As String
Dim speicher As String
Private Sub CommandButton1_Click()
If ComboBox1.Value = "" Then
MsgBox "Bitte tragen Sie eine Ausbildung ein."
Exit Sub
End If
ausbildungSuche.ausbildungCB.Value = ComboBox1.Value
Unload Me
Call ausbildungSuche.suchenBtn_Click
End Sub
Private Sub infoBtn1_Click()
MsgBox "test"
End Sub
Private Sub UserForm_Activate()
On Error GoTo fehler
ComboBox1.List = Sheets("Meta").Range("A1:A8").Value
speicher = ausbildungSuche.ausbildungCB.Value
Select Case speicher
Case "MilFit":
ausbildungNr = "1"
Case "Circuit training":
ausbildungNr = "2"
Case "Volleyball":
ausbildungNr = "3"
Case "Fußball":
ausbildungNr = "4"
Case "Sportliche Ertuechtigung":
ausbildungNr = "5"
Case "BFT":
ausbildungNr = "6"
Case "DSA":
ausbildungNr = "7"
Case "Schwimmen":
ausbildungNr = "8"
Case Else
MsgBox "Fehler"
End Select
Set sh = ThisWorkbook.Worksheets(ausbildungNr)
i = 0
topPos = 12
For Each v In sh.Range("M2:M100")
If Not v = "0" Then
Set frameCard = Controls.add("Forms.Frame.1", "frame" & i)
With frameCard
.Left = 144
.Top = topPos
.Width = 258
.Height = 72
.Caption = ""
.Zoom = 100
.SpecialEffect = 3
.BorderColor = &H80000012
End With
Set cardTitel = frameCard.Controls.add("Forms.Label.1", "cardTitel" & i, True)
With cardTitel
.Left = 8
.Top = 6
.Width = 126
.Height = 18
.ForeColor = &H8000000D
.Caption = v.Cells(, -10)
.FontBold = True
.FontSize = 12
End With
Set infoBtn = frameCard.Controls.add("Forms.CommandButton.1", "infoBtn" & i, True)
With infoBtn
.Left = 144
.Top = 36
.Width = 102
.Height = 24
.ForeColor = &HFFFFFF
.BackColor = &H8000000D
.Caption = v & " Plätze frei"
End With
Debug.Print "infoBtn" & i
Set ausLabel = frameCard.Controls.add("Forms.Label.1", "ausLabel", Visible)
With ausLabel
.Left = 12
.Top = 30
.Width = 42
.Height = 12
.Caption = "Ausbilder"
End With
Set ausbilderLabel = frameCard.Controls.add("Forms.Label.1", "ausbilderLabel", Visible)
With ausbilderLabel
.Left = 54
.Top = 30
.Width = 72
.Height = 12
.FontBold = True
.Caption = v.Cells(, -9)
End With
Set amLabel = frameCard.Controls.add("Forms.Label.1", "amLabel", Visible)
With amLabel
.Left = 12
.Top = 48
.Width = 24
.Height = 12
.Caption = "Am"
End With
Set datumLabel = frameCard.Controls.add("Forms.Label.1", "datumLabel", Visible)
With datumLabel
.Left = 54
.Top = 48
.Width = 72
.Height = 12
.FontBold = True
.Caption = v.Cells(, -8)
End With
Set infoLabel = frameCard.Controls.add("Forms.Label.1", "infoLabel", Visible)
With infoLabel
.Left = 222
.Top = 6
.Width = 24
.Height = 12
.FontBold = True
.Caption = "Info"
End With
topPos = frameCard.Top + frameCard.Height + 10
i = i + 1
End If
Next
ausbildungsfilter.Caption = ausbildungSuche.ausbildungCB.Value
Exit Sub
fehler: MsgBox "Das hat leider nicht geklappt."
Unload Me
End Sub
You need a class module beside the user form. Here is a sample of the mechanic how dynamic events works:
Place this code in the module of an empty user form:
Option Explicit
Dim comSampleBtn1 As clsClickEventsComBut
Dim comSampleBtn2 As clsClickEventsComBut
Private Sub UserForm_Initialize()
Dim comButTemp As MSForms.CommandButton
Dim commandButtonIndex As Byte
commandButtonIndex = 1
'Place sample button 1 and generate click event
Set comButTemp = Me.Controls.Add("Forms.commandbutton.1", "CommandButton" & commandButtonIndex, True)
commandButtonIndex = commandButtonIndex + 1
With comButTemp
'Place button
.Left = 50
.Top = 50
.Height = 20
.Width = 100
.Caption = "Sample Button 1"
.ControlTipText = "Click me"
End With
Set comSampleBtn1 = New clsClickEventsComBut
Set comSampleBtn1.ComButSample = comButTemp
Set comButTemp = Nothing
'Place sample button 2 and generate click event
Set comButTemp = Me.Controls.Add("Forms.commandbutton.1", "CommandButton" & commandButtonIndex, True)
commandButtonIndex = commandButtonIndex + 1
With comButTemp
'Place button
.Left = 50
.Top = 75
.Height = 20
.Width = 100
.Caption = "Sample Button 2"
.ControlTipText = "Click me too"
End With
Set comSampleBtn2 = New clsClickEventsComBut
Set comSampleBtn2.ComButSample = comButTemp
Set comButTemp = Nothing
End Sub
Now you need a class module with the name clsClickEventsComBut
Copy the following code to this module:
Option Explicit
Public WithEvents ComButSample As MSForms.CommandButton
Private Sub ComButSample_Click()
MsgBox "You clicked the sample button: " & UserForm1.ActiveControl.Name & Chr(13) & "With the caption: " & UserForm1.ActiveControl.Caption
End Sub
If you now click one of the two buttons, the message box will be show. This works with all controls.
Edit: New text for the message box with reference to the clicked button.
You have to assign this to the OnClick property of the button (usually on the OnLoad event or something similar):
infoBtn1.OnClick = "[Event Procedure]"
This assumes you have your Private Sub InfoBtn1_Click procedure declared like you have on your example code.
And note that it is this exact "[Event Procedure]" string that should be assigned to the OnClick.
I have a userform with various checkboxes. Each checkbox when selected opens up a new userform with a new set of checkbox, textbox and spinbutton controls based on a column in a worksheet. This column will change and thus there will be a new number of checkboxes, textbox and spinbutton controls every time the macro runs.
I need to use the spinbutton_change() event to set the value of the textbox. Since I don't know the number of spinbuttons that will exist at a given time how can I code this so each spinbutton updates its respective textbox?
Private Sub UserForm_Activate()
Dim NewChkBx As MSForms.CheckBox
Dim NewTxtBx As MSForms.TextBox
Dim NewSpinButton As MSForms.SpinButton
Dim rngSource As Range
Dim rngCell As Range
Dim TopPos As Integer
Dim MaxWidth As Long
Sheets("Background").UsedRange.ClearContents
'Filters items in Col A which Equal "Light"
Application.ScreenUpdating = False
Worksheets("Weight_Data").Unprotect
Worksheets("Background").[a1].CurrentRegion.Offset(1).ClearContents
Worksheets("Weight_Data").Range("D1:D1000").AutoFilter 1, "Light"
Worksheets("Weight_Data").Range("A2:H1000").Copy (Worksheets("Background").Range("A65536").End(xlUp)(2))
Worksheets("Weight_Data").Range("A1").AutoFilter 'Turn Filter Off
' End of filter
' Start of creating new userform based only on checked boxes.
With Worksheets("Background")
Set rngSource = Worksheets("Background").Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With
TopPos = 5
MaxWidth = 0
For Each rngCell In rngSource
If rngCell.Value <> "" Then
Set NewChkBx = Me.Controls.Add("Forms.CheckBox.1")
Set NewTxtBox = Me.Controls.Add("Forms.Textbox.1")
Set NewSpinButton = Me.Controls.Add("Forms.Spinbutton.1")
With NewChkBx
.Caption = rngCell.Value
.Left = 5
.Top = TopPos
.AutoSize = True
If .width > MaxWidth Then MaxWidth = .width
End With
With NewTxtBox
.Enabled = True
.Value = 0
.Enabled = False
.Text = 0
.Height = 15
.width = 20
.Left = NewChkBx.width + 20
.Top = TopPos
.AutoSize = True
If .width > MaxWidth Then MaxWidth = .width
End With
With NewSpinButton
.Value = 0
.Height = 15
.width = 10
.Left = NewTxtBox.width + NewChkBx.width + 20
.Top = TopPos
If .width > MaxWidth Then MaxWidth = .width
End With
TopPos = TopPos + 60
End If
Next rngCell
Me.width = MaxWidth + 60
Me.Height = TopPos + 25
' Worksheets("Weight_Data").Protect
Application.ScreenUpdating = True
Sheets("Background").UsedRange.ClearContents
End Sub
Here's a slightly-simplified version of your code which has some dynamic event capture built in.
Userform:
Option Explicit
Dim col As Collection '<<< needs to be global
Private Sub UserForm_Activate()
Dim x As Long, TopPos As Long, MaxWidth As Long
Dim NewChkBx As MSForms.CheckBox
Dim NewTxtBox As MSForms.TextBox
Dim NewSpinButton As MSForms.SpinButton
Set col = New Collection
TopPos = 5
MaxWidth = 0
For x = 1 To 10
Set NewChkBx = Me.Controls.Add("Forms.CheckBox.1")
Set NewTxtBox = Me.Controls.Add("Forms.Textbox.1")
Set NewSpinButton = Me.Controls.Add("Forms.Spinbutton.1")
With NewChkBx
.Caption = "Number " & x
.Left = 5
.top = TopPos
.AutoSize = True
If .Width > MaxWidth Then MaxWidth = .Width
End With
With NewTxtBox
.Enabled = True
.Value = 0
.Enabled = False
.Text = 0
.Height = 15
.Width = 20
.Left = NewChkBx.Width + 20
.top = TopPos
.AutoSize = True
If .Width > MaxWidth Then MaxWidth = .Width
End With
With NewSpinButton
.Value = 0
.Height = 15
.Width = 10
.Left = NewTxtBox.Width + NewChkBx.Width + 20
.top = TopPos
If .Width > MaxWidth Then MaxWidth = .Width
End With
col.Add CaptureEvents(NewSpinButton, NewTxtBox) '<<< save new class instance
TopPos = TopPos + 20
Next x
Me.Width = MaxWidth + 60
Me.Height = TopPos + 25
End Sub
'Return a new instance of clsEvents with controls added....
Private Function CaptureEvents(spn As MSForms.SpinButton, txt As MSForms.TextBox)
Dim rv As New clsEvents
Set rv.spn = spn
Set rv.tb = txt
Set CaptureEvents = rv
End Function
Class module "clsEvents":
Option Explicit
Public WithEvents spn As MSForms.SpinButton
Public tb As MSForms.TextBox
Private Sub spn_Change()
Me.tb.Text = spn.Value
End Sub
I am trying to create a tool in Excel. My first problem is that I cannot reliably instantiate labels and textboxes on my worksheet. I currently have the code below.
Sub Test2()
Dim Schedule As Worksheet
Set Schedule = Worksheets("Schedule")
'Creates the row number
Schedule.OLEObjects.Add ClassType:="Forms.Label.1"
With Worksheets("Schedule").Label1
.Caption = 1
.width = 18
.Height = 18
.Top = 0
.Left = 0
.SpecialEffect = 1
.BackColor = &H8000000F
.TextAlign = 2
End With
End Sub
and
Sub Test3()
Dim Schedule As Worksheet
Set Schedule = Worksheets("Schedule")
Schedule.OLEObjects.Add ClassType:="Forms.TextBox.1"
With Worksheets("Schedule").TextBox1
.Text = "Task Name"
.width = 200
.Height = 18
.Top = 0
.Left = 18
.SpecialEffect = 0
.BackColor = &H80000005
.TextAlign = 1
.BorderStyle = 1
End With
End Sub
These both work on their own, but when you run one then the other an error is generated
"Run-time error '438': Object doesn't support this property or method".
Any advice?
Also, how would I store and access these labels and text boxes if I have an indefinite amount being created, I assume some sort of collect?
For some of the properties, you'll need to refer to the Object property of the OleoObject object...
Sub Test2()
'Creates the row number
With Worksheets("Schedule").OLEObjects.Add(ClassType:="Forms.Label.1")
.Left = 0
.Top = 0
.Width = 18
.Height = 18
With .Object
.Caption = 1
.SpecialEffect = 1
.BackColor = &H8000000F
.TextAlign = 2
End With
End With
End Sub
Sub Test3()
With Worksheets("Schedule").OLEObjects.Add(ClassType:="Forms.TextBox.1")
.Left = 18
.Top = 0
.Width = 200
.Height = 18
With .Object
.Text = "Task Name"
.SpecialEffect = 0
.BackColor = &H80000005
.TextAlign = 1
.BorderStyle = 1
End With
End With
End Sub
Hope this helps!
I'm trying to assign event handlers on a dynamic userform in excel and let's just say that I can't find the answer, at least none I can get to work. I need Event handled on the checkbox...
Private Sub UserForm_Initialize()
Feuil1.Select
ThisWorkbook.Generate_Client_List
Dim i As Integer
i = 1
Dim topref As Integer
topref = 25
Dim imgFile1 As Object
Set imgFile1 = Client_picking.Controls.Add("Forms.Image.1")
With imgFile1
.Left = 140
.Height = 40
.Width = 40
.Picture = LoadPicture("C:\Users\Temp\Desktop\Project\excel.jpg")
End With
Dim imgFile As Object
Set imgFile = Client_picking.Controls.Add("Forms.Image.1")
With imgFile
.Left = 180
.Height = 40
.Width = 40
.Picture = LoadPicture("C:\Users\Temp\Desktop\Project\mail.jpg")
End With
Dim Label As Object
Set Label = Client_picking.Controls.Add("Forms.Label.1")
With Label
.Caption = "Clients"
.Left = 35
.top = topref - 15
.Width = 90:
.Height = 20
.Object.BackStyle = 0
End With
For Each distinctClientList In Feuil1.Range("DA3:DA10").Cells
Dim MaCheckBox As Object
Set MaCheckBox = Client_picking.Controls.Add("Forms.CheckBox.1")
With MaCheckBox
.Caption = "fichier"
.Left = 140
.top = topref + (20 * i)
End With
Dim MaCheckBoxmail As Object
Set MaCheckBoxmail = Client_picking.Controls.Add("Forms.CheckBox.1")
With MaCheckBoxmail
.Caption = "mail"
.Left = 180
.top = topref + (20 * i)
End With
Dim MaTextBox As Object
Set MaTextBox = Client_picking.Controls.Add("Forms.TextBox.1")
With MaTextBox
.Text = CStr(distinctClientList.Value)
.Left = 20
.top = topref + (20 * i)
.Width = 90:
.Height = 20
End With
i = i + 1
Next
Dim MyButton As Object
Set MyButton = Client_picking.Controls.Add("Forms.CommandButton.1")
With MyButton
.top = topref + (20 * i) + 20
.Left = 100
.Caption = "Ok"
End With
Client_picking.Height = topref + (20 * i) + 100
ThisWorkbook.Clear_Client_List
ClearToggleList
End Sub
The end result:
I have some problems with an interface I'm making. I'm new to this and after a lot of search, I finally gave up and came here to ask.
First of all I made my code do this:
Open a userform from a button on a sheet.
After the userform is open, it has some default fields (some textboxes, a label and a commandbutton).
Then you have a commandbutton that creates a new round of fields and assign them a class to execute some simple code (numerical restriction for some textboxes and create a new textbox with content for the button).
My problem is the following :
I tried to assign ControlSource to the fields but Excel doesnt allow me to, and the only time it allowed me to, the fields didn't update the cell nor the cell updated the field.
I also tried to load the value from the newly created field directly into the sheet but I don't know how to call the object and get its properties.
Here is the code I'm using :
Option Explicit
Dim cargarconcepto() As New Clase3
Private Sub CommandButton19_Click()
Dim txtCtl As Control
Dim concepto As Object
Dim i As Long
i = labelcounter
controlextra = controlextra + 1
Dim Label As Object
Dim lblctr As Long
Dim nmctr As Long
Dim t1 As Object
Dim t2 As Control
Dim t3 As Control
Dim t4 As Control
Dim t5 As Object
Dim t6 As Object
Dim cargaconcepto As Control
UserForm1.Frame21.ScrollHeight = 80 + (25 * controlextra) - 25
UserForm1.Frame21.ScrollTop = UserForm1.Frame21.ScrollHeight
nmctr = labelcounter + 1
For lblctr = labelcounter To controlextra
Set Label = UserForm1.Frame21.Controls.Add("Forms.Label.1", "Labelt" & labelcounter, True)
With Label
.Caption = "0005 - "
.Left = 3
.Height = 12
.Width = 24
.Top = 25 + (25 * labelcounter)
End With
Set t1 = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "t" & labelcounter + 1 & "1", True)
With t1
.value = Workbooks("A Facturar Proyecto tarjetas.xlsm").Sheets("Data").Range("as1").value
.Left = 31
.TextAlign = fmTextAlignCenter
.Enabled = False
.Height = 15.75
.Width = 54
.Top = 25 + (25 * labelcounter)
End With
Set t2 = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "t" & labelcounter + 1 & "2", False)
With t2
.value = ""
.Left = 97
.Height = 15.75
.Width = 90
.Top = 25 + (25 * labelcounter)
.Visible = True
End With
Set t3 = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "t" & labelcounter + 1 & "3", False)
With t3
.value = ""
.Left = 199
.Height = 15.75
.Width = 90
.Top = 25 + (25 * labelcounter)
.Visible = True
End With
Set t4 = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "t" & labelcounter + 1 & "4", False)
With t4
.value = ""
.Left = 307
.Height = 15.75
.Width = 90
.Top = 25 + (25 * labelcounter)
.Visible = True
End With
Set t5 = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "t" & labelcounter + 1 & "5", True)
With t5
.value = ""
.Left = 415
.Height = 15.75
.Width = 90
.Top = 25 + (25 * labelcounter)
End With
Set t6 = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "t" & labelcounter + 1 & "6", True)
With t6
.value = ""
.Left = 517
.Height = 15.75
.Width = 90
.Top = 25 + (25 * labelcounter)
End With
Set concepto = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "concepto" & labelcounter + 1, False)
With concepto
.value = ""
.BackStyle = fmBackStyleTransparent
.Left = 619
.Height = 20
.Width = 210
.Top = 25 + (25 * labelcounter)
.Enabled = False
.value = Workbooks("A Facturar Proyecto tarjetas").Sheets("Data").Range("Ac45")
.Visible = True
End With
Set cargaconcepto = UserForm1.Frame21.Controls.Add("forms.commandbutton.1", "Cargar Concepto" & labelcounter + 1, False)
With cargaconcepto
.Caption = "Cargar Concepto"
.Left = 834
.Height = 20
.Width = 90
.Top = 25 + (25 * labelcounter)
.Tag = labelcounter + 1
.Visible = True
End With
ReDim Preserve num(1 To i)
Set num(i).txtCtrl = t2
ReDim Preserve num2(1 To i)
Set num2(i).txtCtrl = t3
ReDim Preserve num3(1 To i)
Set num3(i).txtCtrl = t4
ReDim Preserve cargarconcepto(1 To i)
Set cargarconcepto(i).cargar = cargaconcepto
Set cargaconcepto = Nothing
Set t3 = Nothing
Set t4 = Nothing
Set t2 = Nothing
labelcounter = labelcounter + 1
Next
End Sub
And then here is the class:
Option Explicit
Public WithEvents cargar As MSForms.CommandButton
Private Sub cargar_Click()
Dim concepto As Control
Set concepto = UserForm1.Frame21.Controls.Add("Forms.TextBox.1", "concepto" & labelcounter + 1, True)
With concepto
.value = ""
.BackStyle = fmBackStyleTransparent
.Left = 619
.Height = 20
.Width = 210
.Top = (25 * b)
.Enabled = False
.value = Workbooks("A Facturar Proyecto tarjetas").Sheets("Data").Range("Ac45")
End With
End Sub
I tried to use something like UserForm1.Frame21.concepto & cargar.Tag to get the name of the newly created field and therefore replace its value for a new one AND to load that value into the sheet.
But I just cant find a way to do it. Now I have an almost complete interface for data entry but I cant drop the data into the spreadsheet.
Please I need help!