Hi all, I get the following error "Method 'range of object' - Global failed" when I run the code below. It's the Set objButton line that causes the problem. Can anybody explain what I need to do to fix it from going into error? thanks, Neil
Private Sub AddButtons()
Dim objButton As OLEObject
Dim wsd As Worksheet
Dim finalrow As Single
Set wsd = Worksheets("MainData") 'Select worksheet
finalrow = wsd.Cells(Application.Rows.Count, 1).End(xlUp).row 'Find final row
CalcRowHeight 'Call procedure to calculate position to place button
'Add button
Set objButton = wsd.OLEObjects.Add _
(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=1000, Top:=strTop, Width:=153, Height:=80)
'Assign propeties to button
With objButton
.Name = "Adjust_Main_Data"
.Object.Caption = "Adjust Main Data"
.Object.FontSize = 14
.Object.FontName = "Verdana"
.Object.Font.Bold = True
.Object.ForeColor = vbBlack
.Object.BackColor = vbRed
'Set ThisWorkbook.CommandButtonEvent = objButton.Object
End With
Range("C2:" & StrRowNo).Select
Selection.NumberFormat = "0" 'Format column for number to enable show code report
End Sub
Bookmarks