Hi
I have some code that adds or removes a button, an adaption code I found. I want to be able to set the font & it's colour but am failing. Also the ButtonName has no effect - I would like to set the name.
What have I done wrong ?
I have some code that adds or removes a button, an adaption code I found. I want to be able to set the font & it's colour but am failing. Also the ButtonName has no effect - I would like to set the name.
What have I done wrong ?
Code:
Sub AddButton()
Dim ctop#, cleft#, cht#, cwdth#
Dim sht As Worksheet
Dim Btn As OLEObject
On Error Resume Next
Set sht = ThisWorkbook.Worksheets("Summary")
With Range("h34")
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
With sht.OLEObjects("CommandButton1").Object
.BackColor = RGB(199, 21, 133)
.Name = "ChkAc"
.Placement = xlMoveAndSize
.Font.Color = RGB(255, 228, 225)
.Font.Name = "Trebuchet MS"
.Font.FontStyle = "Italic"
.Font.Size = 10
.Caption = "Check"
End With
End Sub
Sub RemoveButton()
Worksheets("Summary").OLEObjects("CommandButton1").Delete
Application.EnableEvents = True
End Sub
Private Sub CommandButton1_Click()
Dim CustRow As Integer
Worksheets("Overdue Debtors").Select
CustRow = Range("H33").Value
ActiveSheet.Cells(CustRow, 1).Select
End Sub