Locating Form Control Buttons

dbodimer

New Member
Joined
Jul 15, 2015
Messages
36
I am trying to create and locate Form Control Buttons in a Worksheet using VBA code. I am trying to get the buttons to align with cell boundaries on the worksheet. What I don't know is how to tell the ActiveSheet.Buttons.Add code to align the button boundaries with cell boundaries.

E.G. cell D3 is a merged cell (D3:E4). I would like to place a button on cell D3 such that the button boundaries match the cell boundaries.

Any thoughts?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
One way

Code:
Sub CreateButton()
    Dim cb As Object, rCell As Range
            
    With Sheets("Sheet1") ' <--Adjust sheetname
        Set rCell = .Range("D3:E4")
        Set cb = .Buttons.Add(rCell.Left, rCell.Top, rCell.Width, rCell.Height)
        With cb
            .Caption = "Test"
            .OnAction = "Test"
        End With
    End With
End Sub

Sub Test()
    MsgBox "Hello World!"
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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