Regarding VBE. If a worksheet does not exist it will create it and add a commandbutton at Sheet1. It will also add the appr. code for the private sub commandbutton1_click. This works all fine. This is part of the existing code that will add a new sub:
Dim Code as String
Code = "Private sub CommandButton1_Click()" & vbCrLf
[..]
Code = Code & "End Sub"
With ThisWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
.insertlines .CountOfLines + 1, Code
However before adding that 'sub code', it should check if in the already existing (object) the sub code (for commandbutton1) already exists and if so, then delete it before adding new code.