I am currently trying to create a command button when a new sheet is created. However I'm facing an error. Error 438, object doesn't support this property or method. Need some assistance here. Cheers.
Code:
<CODE>Sub wdlsinflow()
Dim r As Range, LstRw As Long, LstCo As Long
Dim Obj As Object
Dim Code As String
LstRw = Sheets("sheet2").Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
LstCo = Sheets("sheet2").Cells.Find(What:="*", SearchOrder:=xlColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column
Const myCompany As String = "RECEIVABLES - INFLOWS"
Set r = Sheets("sheet2").Columns(1).Find(myCompany, , , 1)
If Not r Is Nothing Then
If Not IsSheetExists(myCompany) Then
Sheets.Add(After:=Sheets(Sheets.Count)).Name = myCompany
End If
With Sheets(myCompany)
.Cells.Clear
Range(r, Sheets("sheet2").Cells(LstRw, LstCo)).Copy .Cells(1)
Set Obj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=200, Top:=100, Width:=100, Height:=35)
Obj.Name = "TestButton"
'buttonn text
ActiveSheet.OLEObjects(1).Object.Caption = "Test Button"
Code = "Sub ButtonTest_Click()" & vbCrLf
Code = Code & "Call Tester" & vbCrLf
Code = Code & "End Sub"
End With
End If
With Sheets(myCompany).VBProject.VBComponents(Sheets(myCompany).Name).CodeModule
.insertlines .CountOfLines + 1, Code
End With
End Sub</CODE>