Adding checkbox within a frame

G

Guest

I have couple of 100 templates and inorder to make a global change (Adding a
frame and a checkbox on form) to all of them, i was trying the below
mentioned code.

What i was doing was opening each template at time..making the design time
change and saving it before closing.

Problem : It adds the frame and then the checkbox on the form. But i want to
add the checkbox in the frame. Any ideas!...


Sub Add_Control()
' Declare variables.
Dim mynewform As Object
Dim myframe As Object
Dim mycheckbox As Object
' to manipulate the UserForm.
Set mynewform =
Workbooks(workbook_Name).VBProject.VBComponents.Item(form_Name)

'Adding a frame
Set myframe = mynewform.Designer.Controls.Add("Forms.Frame.1")
With myframe
.Name = "frame1"
.Top = 180
.Left = 390
.Height = 60
.Width = 202
.BorderStyle = 1
End With

'Add a checkbox.
Set mycheckbox = mynewform.Designer.Controls.Add("Forms.checkBox.1")
With mycheckbox
.Name = "chk_1"
.Top = 6
.Left = 6
.Height = 14.25
.Width = 198
End With

End Sub
 
B

Bernie Deitrick

Ajit,

Try changing
Set mycheckbox = mynewform.Designer.Controls.Add("Forms.checkBox.1")
to
Set mycheckbox = myframe.Designer.Controls.Add("Forms.checkBox.1")

so that you are adding the control to the frame, not the form.

HTH,
Bernie
MS Excel MVP
 

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