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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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