0

I'm trying to add a new CheckBox when the "Sensitive data" checkbox is checked and have the same height and width as the others.

I've just see this answer and it works, the code adds a new checkbox, but its like below

this

I want the "Checkbox" to have a name, like chkPCI, and the caption "PCI", I've tried the following code, but adds a form control, and not an ActiveX control.

    ActiveSheet.CheckBoxes.Add(Cells(10, "A").Left, _
                            Cells(10, "A").Top, _
                            72, 17.25).Select
    With Selection
        .Caption = "PCI"
        .Value = xlOff '
        .Display3DShading = False
    End With
Bryan Arreola
  • 197
  • 1
  • 6
  • 22
  • 2
    You'll want to do this though the sheet's `OLEObjects` collection - see the answer on the linked post/duplicate. Note that the OLEObject's `Object` property will be your `MSForms.Checkbox` control - you'll want to have a `Dim chkBox As MSForms.CheckBox` variable to access the members, otherwise working with the `Object` property will be all late-bound, which is like coding blindfolded (expect error 438 if you make a mistake) – Mathieu Guindon Nov 12 '19 at 20:17
  • @MathieuGuindon Awesome, thanks, I'll let you know if a I make it work. – Bryan Arreola Nov 12 '19 at 21:02
  • @MathieuGuindon I ran into the error you just wrote, this is the code [link](https://pastebin.com/bxpnKh6h), it creates the CheckBox, but absolutely ignores the `With objChkBx` code – Bryan Arreola Nov 13 '19 at 19:26
  • 1
    Declare `objChkBx` (could use a few more vowels...) with `Dim objChkBx As MSForms.CheckBox`, and then change your code to do `With Sheets("...").OLEObjects.Add(...)`. Then inside the `With` block, do `Set objChkBx = .Object`. Now you have an early-bound checkbox object and you'll get intellisense/autocompletion for the member calls against it. – Mathieu Guindon Nov 13 '19 at 19:29
  • I just did, and it's exactly what I was looking for, thanks a lot! – Bryan Arreola Nov 13 '19 at 19:41

0 Answers0