ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding checkbox within a frame (https://www.excelbanter.com/excel-programming/319462-adding-checkbox-within-frame.html)

Ajit

Adding checkbox within a frame
 
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.It em(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

--
Ajit

Bernie Deitrick

Adding checkbox within a frame
 
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

"Ajit" wrote in message
...
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.It em(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

--
Ajit





All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com