I believe the code below is correct; it's derived from a Chip page. The problem is that I can run test1 to create click code for myButton1, no problem. Or I can run test2 to create click code for myButton2, fine. But I can't do BOTH. That is, not back to back: test_two_creations_always_goes_boom violently crashes every time.

My theory is that there is a flawed incompatibility between ActiveX controls and interactive VBA code. I've encountered this when doing button creation, e.g.
activesheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1")
giving the lame message "can't enter break mode at this time" if you step or use breakpoints. I've also had problems when doing DAO ops from ActiveX buttons.

Note this may be version specific; I'm on 2003.

In order to reproduce, in a fresh book, first create two activeX command buttons. In 2003 that's View/Toolbar/Control Toolbox and drag command button to sheet (twice) to create them. Then in design mode, right click, properties, and name them myButton1 and myButton2.Note, this is all on the worksheet; no Forms. You might need to add a VBA reference to Microsoft VBA Extensibility. I recommend that you SAVE the file after creating the buttons, because you're about to go boom and have to rebuild them otherwise.

Kind warning, again: don't have unsaved or corruptible workbooks open. Excel is going down if you test the above. (Maybe you won't crash. Maybe I'm just corrupt. But I do have that oh-so-rare condition right now where I reproduce the success every time and reproduce the failure every time, repeatedly.)

So is there something I can do differently to avoid the crash, besides having to run the routines one at a time?
sub test1
    test_addClickEventCode ActiveSheet.Name, "myButton1", "Click", "msgbox ""hello click"" "	' fine for 1 call
end sub

sub test2
    test_addClickEventCode ActiveSheet.Name, "myButton2", "Click", "msgbox ""hello clickclick"" "	' fine for 1 call
end sub

Sub test_two_creations_always_goes_boom()
    call test1
    call test2
End Sub

Sub test_addClickEventCode(sCodeMod As String, sObjName As String, sEventName As String, S As String)
                  Rem e.g. "Sheet2",           "MyButton1",        "Click",              "(Code with linefeeds)"
    Dim CodeMod As VBIDE.CodeModule
    Dim LineNum As Long

    Set CodeMod = ThisWorkbook.VBProject.VBComponents(sCodeMod).CodeModule
    With CodeMod
        LineNum = .CreateEventProc(sEventName, sObjName)
        LineNum = LineNum + 1
        .InsertLines LineNum, S
    End With
End Sub