Automating the Creation of Checkboxes using VBA in Excel

N

Noel

I am trying to create a semi-automated system using VBA in Excel and
need some help in creating an interface for user input.

With each use of the tool I am building, it needs to create
automatically a different number of user forms with a varying number
of checkboxes in each one. Not only will the number of user forms
change with each use of the tool, but so also will the number of
checkboxes on each user form. Does anyone have an idea as to how to do
this?

Thanks in advance....
 
L

Luca Brasi

Create a userform (named "UserForm1") in a new vba project. Then copy
following code lines into a module and run the "Test" procedure.

' **** Start of code ****
Sub Test()
Dim u As UserForm1
Dim chk As MSForms.CheckBox
Dim i As Long
Dim j As Long
For i = 0 To 3
Set u = New UserForm1
With u
.Caption = "Form " & CStr(i)
For j = 0 To i
Set chk = .Controls.Add("Forms.CheckBox.1")
chk.Caption = "Checkbox " & CStr(j)
chk.Left = 12
chk.Top = 12 + (j * 15)
Next j
.Show False
.Top = .Top + (i * 30)
.Left = .Left + (i * 30)
End With
Next i
Set chk = Nothing
Set u = Nothing
End Sub
' **** End of code ****

I did this code in PowerPoint 2007, but I guess it should run in other
Office applications/versions as well.

Luc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top