Macro - ActiveX Checkbox - linked cell

esauowain

New Member
Joined
Dec 8, 2016
Messages
2
Hi;

I'm trying to modify a macro that will:


  1. create an activeX checkbox in a cell range
  2. Link the checkbox to the relevent cell
  3. Change the background of the checkbox to transparent
  4. Change the object position to "Move and size with cells"
I can only seem to get it to create the basic checkboxes in the cells, every time i try link them to cells i get erros. The code i have so far is:

Code:
Sub ActX_Add_Multiple_CheckBox_Ex2()

    'Disable Screen Update
    Application.ScreenUpdating = False
    'Variable Declaration
    Dim Rng As Range
    Dim ShtRng As Range
    Dim WrkSht As Worksheet
    Set ShtRng = Application.Selection
    Set ShtRng = Application.InputBox("Range", "Analysistabs", ShtRng.Address, Type:=8)
    Set WrkSht = Application.ActiveSheet
    
    For Each Rng In ShtRng
        WrkSht.OLEObjects.Add "Forms.CheckBox.1", Left:=Rng.Left, Top:=Rng.Top, Width:=Rng.Width, Height:=Rng.Height
    Next
    
    ShtRng.ClearContents
    ShtRng.Select
    
    'Enable Screen Update
    Application.ScreenUpdating = True
    
End Sub

Any help on this would be greatly appreciated.

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this:
Code:
Public Sub Add_ActiveX_Checkboxes()

    Dim wks As Worksheet
    Dim cell As Range, checkboxCells As Range
    Dim objOLE As OLEObject
    
    Set wks = ActiveSheet
    
    Set checkboxCells = Application.Selection
    Set checkboxCells = Application.InputBox("Range", "Analysistabs", checkboxCells.Address, Type:=8)
    
    For Each cell In checkboxCells
    
        Set objOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1")

        With objOLE
            .Left = cell.Left
            .Top = cell.Top
            .Width = cell.Width
            .Height = cell.Height
            .name = "Checkbox_" & cell.Address
            .LinkedCell = cell.Worksheet.name & "!" & cell.Address
            '.Placement = xlMove
            .Placement = xlMoveAndSize
            .Object.Value = False
            .Object.BackStyle = fmBackStyleTransparent
            '.Object.BackStyle = fmBackStyleOpaque
            .Object.TripleState = False 'True
            .Object.Caption = ""
        End With
    
    Next

End Sub
 
Upvote 0
Hi;

Thanks for the reply, the script runs but it doesn't link it to the cell. The linked cell (under properties) is still blank.

Also the transparency doesnt work. It does actually set the property value to fmBackStyleTransparent but its still showing as opaque.

Regards
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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