Embed Command Button in Cell

  • Thread starter Thread starter Bythsx-Addagio
  • Start date Start date
B

Bythsx-Addagio

Hello,
I would like to set a command button or other control inside a worksheet
cell. Essentially I am hoping ot have a clearly identifable button which
sits in the space of a particular cell. Does anyone know if this is possible?

Thanks for your help!
 
Following should size your control to a cell and set its "Move and Size"
property

Sub test()
Dim obj As Object

Set obj = Selection ' eg, Forms button, rectangle etc

' maybe a Controls Toolbox button
'Set obj = ActiveSheet.OLEObjects("CommandButton1")

' some shape
' Set obj = ActiveSheet.Shapes("Rectangle 6")

If TypeName(obj) = "Shape" Then Set obj = obj.DrawingObject

SizeToCell obj, Range("D4") ' optionally set to a cell

End Sub

Sub SizeToCell(dwo As Object, Optional rTopLeft As Range)
Dim c As Range
With dwo
If rTopLeft Is Nothing Then
Set c = .TopLeftCell
Else
Set c = rTopLeft
End If
.Left = c.Left
.Top = c.Top
.Width = c.Width
.Height = c.Height
.Placement = xlMoveAndSize
End With
End Sub


Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top