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?
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,344
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.
 

Forum statistics

Threads
1,085,495
Messages
5,384,002
Members
401,871
Latest member
allemandi

Some videos you may like

This Week's Hot Topics

Top