Sub initButton()
Dim ButtonCell As Range
Set ButtonCell = Pr.Range("N15")
ButtonCell.Activate
For i = 15 To (tableContentRows + 14)
Call AddButton
Pr.OLEObjects("Line" & i).Visible = True
ActiveCell.Offset(1, 0).Activate
Next i
End Sub
Sub AddButton()
Dim buttonForMasterSparePart As OLEObject
With ActiveCell
Set buttonForMasterSparePart = ActiveSheet.OLEObjects.Add _
(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, _
Top:=.Top, _
Height:=.Height, _
Width:=.Width)
buttonForMasterSparePart.Object.Caption = .row
buttonForMasterSparePart.Object.Font.Size = 6
buttonForMasterSparePart.Object.Font.Bold = True
buttonForMasterSparePart.Object.WordWrap = True
buttonForMasterSparePart.Name = "Line" & .row
buttonForMasterSparePart.Object.Font.Name = "MS Gothic"
End With
' Inserts code for the button
With ThisWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Sub " & buttonForMasterSparePart.Name & "_Click()"
.InsertLines Line + 2, "sendData(" & ActiveCell.row & ")"
.InsertLines Line + 3, "End Sub"
End With
End Sub