phantom1975
MrExcel MVP
- Joined
- Jun 3, 2002
- Messages
- 3,962
What can be done to make a command button fit PERFECTLY inside of one cell?
Sub CreateFormsButton()
Dim btn As Button
Dim rng As Range
With Worksheets("Sheet1")
Set rng = .Range("C5")
Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
With btn
.Caption = "Test"
.OnAction = "Test1"
End With
End With
End Sub
Sub CreateCommandButton()
Dim ctop#, cleft#, cht#, cwdth#
Dim sht As Worksheet
Dim Btn As OLEObject
Set sht = ThisWorkbook.Worksheets("Sheet1")
With Range("C10")
ctop = .Top
cleft = .Left
cht = .Height
cwdth = .Width
End With
With sht
Set Btn = .OLEObjects.Add(ClassType:="Forms.CommandButton.1", Left:=cleft, Top:=ctop, Width:=cwdth, Height:=cht)
End With
Btn.Object.Caption = "Click Me"
Btn.Name = "MyButton"
Btn.Placement = xlMoveAndSize
'Optional code insertion - - establish ref in VBE to MS VBA Extensibility 5.3 Library
With ThisWorkbook.VBProject.VBComponents(sht.CodeName).CodeModule
.InsertLines .CreateEventProc("Click", Btn.Name) + 1, "Msgbox ""Replace this message with your actual code."" "
End With
End Sub
Hi Tom - I've never seen a variable declaration with written with a # at the end. What does that mean?
Dim ctop#, cleft#, cht#, cwdth#