Checkbox on the edge of a frame?

Nikata

New Member
Joined
Jul 9, 2024
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hay all,

I've been trying to get 2 dynamically created checkboxes next to the caption of a dynamically created frame.
Here is a picture of the closest I've gotten, where the checkboxes are inside the frame.
1732629768149.png

I've tried making the checkboxes outside the frame but then they are overlapped by the frame and I am unable to bring them forward.
1732629963716.png

The code to create them:
VBA Code:
'....Code for the rest of the macro
        ' Create individual frames for each day within the main frame
        dayTopPosition = 4
        dayLeftPosition = 4

For dayOfWeek = LBound(dayNames) To UBound(dayNames)       
         ' Create a frame for each day
        Set dayFrame = page.WS.Controls.Add("Forms.Frame.1", "Frame" & dayNames(dayOfWeek))
        dayFrame.Caption = dayNames(dayOfWeek)
        dayFrame.Top = dayTopPosition
        dayFrame.Left = dayLeftPosition
        dayFrame.Width = 340
        dayFrame.Height = 120
        dayFrame.ScrollBars = fmScrollBarsVertical
        dayFrame.ScrollHeight = topPosition

        topPosition = 10 ' Reset top position for checkboxes
        
        ' Add "Week" checkbox at the top of the day's frame
        Set ckbWeek = page.WS.Controls.Add("Forms.CheckBox.1", "ckbWeek_" & dayNames(dayOfWeek))
        ckbWeek.Caption = "Weekly sample"
        ckbWeek.Top = dayTopPosition
        ckbWeek.Left = 50
        ckbWeek.Width = 80
        ckbWeek.BordersSuppress = True

        ' Create and assign event handler for ckbWeek
        Dim chkHandlerWeek As CkbHandler
        Set chkHandlerWeek = New CkbHandler
        chkHandlerWeek.Init ckbWeek, dayNames(dayOfWeek)
        checkboxHandlers.Add chkHandlerWeek
        
        ' Add "Month" checkbox next to the "Week" checkbox
        Set ckbMonth = page.WS.Controls.Add("Forms.CheckBox.1", "ckbMonth_" & dayNames(dayOfWeek))
        ckbMonth.Caption = "Monthly sample"
        ckbMonth.Top = dayTopPosition
        ckbMonth.Left = ckbWeek.Left + 80
        ckbMonth.Width = 80
        ' Create and assign event handler for ckbMonth
        Dim chkHandlerMonth As CkbHandler
        Set chkHandlerMonth = New CkbHandler
        chkHandlerMonth.Init ckbMonth, dayNames(dayOfWeek)
        checkboxHandlers.Add chkHandlerMonth

'Code for the rest of the macro....
        dayTopPosition = dayTopPosition + dayFrame.Height + 5
Next dayOfWeek
Is it possible and if so, does anybody know how?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try adjusting the top position of the checkboxes:

Rich (BB code):
Private Sub CommandButton1_Click()
'....Code for the rest of the macro
        ' Create individual frames for each day within the main frame
        dayTopPosition = 20
        dayLeftPosition = 4
For dayOfWeek = LBound(dayNames) To UBound(dayNames)
         ' Create a frame for each day
        Set dayFrame = Page.WS.Controls.Add("Forms.Frame.1", "Frame" & dayNames(dayOfWeek))
        dayFrame.Caption = dayNames(dayOfWeek)
        dayFrame.Top = dayTopPosition
        dayFrame.Left = dayLeftPosition
        dayFrame.Width = 340
        dayFrame.Height = 120
        dayFrame.ScrollBars = fmScrollBarsVertical
        dayFrame.ScrollHeight = topPosition

        topPosition = 10 ' Reset top position for checkboxes
       
        ' Add "Week" checkbox at the top of the day's frame
        Set ckbWeek = Page.WS.Controls.Add("Forms.CheckBox.1", "ckbWeek_" & dayNames(dayOfWeek))
        ckbWeek.Caption = "Weekly sample"
        ckbWeek.Top = dayTopPosition - 15
        ckbWeek.Left = 50
        ckbWeek.Width = 80
        ckbWeek.BordersSuppress = True

        ' Create and assign event handler for ckbWeek
        Dim chkHandlerWeek As CkbHandler
        Set chkHandlerWeek = New CkbHandler
        chkHandlerWeek.Init ckbWeek, dayNames(dayOfWeek)
        checkboxHandlers.Add chkHandlerWeek
       
        ' Add "Month" checkbox next to the "Week" checkbox
        Set ckbMonth = Page.WS.Controls.Add("Forms.CheckBox.1", "ckbMonth_" & dayNames(dayOfWeek))
        ckbMonth.Caption = "Monthly sample"
        ckbMonth.Top = dayTopPosition - 15
        ckbMonth.Left = ckbWeek.Left + 80
        ckbMonth.Width = 80
        ' Create and assign event handler for ckbMonth
        Dim chkHandlerMonth As CkbHandler
        Set chkHandlerMonth = New CkbHandler
        chkHandlerMonth.Init ckbMonth, dayNames(dayOfWeek)
        checkboxHandlers.Add chkHandlerMonth

'Code for the rest of the macro....
        dayTopPosition = dayTopPosition + dayFrame.Height + 15
Next dayOfWeek
End Sub

Example:

1732632877610.png
 
Upvote 0
Thank you for your answer DanteAmor. This however places the checkboxes above the frame edge.
I've made this with Paint to show the desired positioning:
1732634089200.png

Like I said before, I've got no idea if its possible with dynamic boxes and frames.
 
Upvote 0
Maybe:

1732641162088.png


Change this:

Rich (BB code):
        ' Add "Week" checkbox at the top of the day's frame
        Set ckbWeek = dayFrame.Controls.Add("Forms.CheckBox.1", "ckbWeek_" & dayNames(dayOfWeek))
        ckbWeek.Caption = "Weekly sample"
        ckbWeek.Top = -3
        ckbWeek.Left = 50
        ckbWeek.Width = 80
        ckbWeek.BordersSuppress = True

'...
        
        ' Add "Month" checkbox next to the "Week" checkbox
        Set ckbMonth = dayFrame.Controls.Add("Forms.CheckBox.1", "ckbMonth_" & dayNames(dayOfWeek))
        ckbMonth.Caption = "Monthly sample"
        ckbMonth.Top = -3
        ckbMonth.Left = ckbWeek.Left + 80
        ckbMonth.Width = 80
 
Upvote 0
Thats what I had initially
But the code you put didn't do that, that's why I modified your code.

I guess its not possible to have them on the edge/line.
Something like this:
1732802613527.png

It occurs to me that we can add another frame, and in that frame the checkboxes:

Rich (BB code):
'....Code for the rest of the macro
        ' Create individual frames for each day within the main frame
        dayTopPosition = 4
        dayLeftPosition = 4
        
  For dayOfWeek = LBound(dayNames) To UBound(dayNames)
         ' Create a frame for each day
        Set dayFrame = Page.WS.Controls.Add("Forms.Frame.1", "Frame" & dayNames(dayOfWeek))
        dayFrame.Caption = dayNames(dayOfWeek)
        dayFrame.Top = dayTopPosition
        dayFrame.Left = dayLeftPosition
        dayFrame.Width = 340
        dayFrame.Height = 120
        dayFrame.ScrollBars = fmScrollBarsVertical
        dayFrame.ScrollHeight = topPosition
        dayFrame.ZOrder 1

         ' Create a frame for checkbox
        Set dayFramecb = Page.WS.Controls.Add("Forms.Frame.1", "FrameCb" & dayNames(dayOfWeek))
        dayFramecb.Caption = ""
        dayFramecb.Top = dayTopPosition - 10
        dayFramecb.Left = dayLeftPosition + 60
        dayFramecb.Width = 250
        dayFramecb.Height = 20
        dayFramecb.SpecialEffect = fmSpecialEffectFlat
        dayFramecb.ZOrder 0

        ' Add "Week" checkbox at the top of the day's frame
        Set ckbWeek = dayFramecb.Controls.Add("Forms.CheckBox.1", "ckbWeek_" & dayNames(dayOfWeek))
        ckbWeek.Caption = "Weekly sample"
        ckbWeek.Top = 5
        ckbWeek.Left = 10
        ckbWeek.Width = 100
        ckbWeek.BordersSuppress = True

        ' Create and assign event handler for ckbWeek
'        Dim chkHandlerWeek As CkbHandler
'        Set chkHandlerWeek = New CkbHandler
'        chkHandlerWeek.Init ckbWeek, dayNames(dayOfWeek)
'        checkboxHandlers.Add chkHandlerWeek
        
        ' Add "Month" checkbox next to the "Week" checkbox
        Set ckbMonth = dayFramecb.Controls.Add("Forms.CheckBox.1", "ckbMonth_" & dayNames(dayOfWeek))
        ckbMonth.Caption = "Monthly sample"
        ckbMonth.Top = 5
        ckbMonth.Left = ckbWeek.Left + 100
        ckbMonth.Width = 80
        ckbMonth.BordersSuppress = True

        ' Create and assign event handler for ckbMonth
'        Dim chkHandlerMonth As CkbHandler
'        Set chkHandlerMonth = New CkbHandler
'        chkHandlerMonth.Init ckbMonth, dayNames(dayOfWeek)
'        checkboxHandlers.Add chkHandlerMonth

'Code for the rest of the macro....
        dayTopPosition = dayTopPosition + dayFrame.Height + 15
  Next dayOfWeek


;)
 
Upvote 0
Solution

Forum statistics

Threads
1,225,626
Messages
6,186,096
Members
453,337
Latest member
fiaz ahmad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top