View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mark Kubicki Mark Kubicki is offline
external usenet poster
 
Posts: 89
Default programming the VBE for a new event procedure

i had to change the line to be 2-part
msgtext = "You done it"
.InsertLines StartLineNum, (MsgBox(msgText, vbOKOnly))
this eliminated a error i was getting with the code
however, the event handler error is still there

i tried this alternate approach which did create the code, but the code does not function when i press the newly created command button
(ALL OF THIS IS HAPPENING ON THE SAME FORM WHICH REMAINS LOADED AND OPEN FOR THE DURATION -is this part of the problem?)


Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("frmTimeClock" ).CodeModule
With VBCodeMod
msgtext = "you done it"
StartLineNum = .CountOfLines + 1
.InsertLines StartLineNum, "Private sub " & mycmd.Name & "_click()" & Chr(13) & _
"msgbox (msgtext)" & Chr(13) & _
"end sub"
End With

additionally, after running this procedure, i will get this message upon clicking another (but not all) of the other command buttons on the sheet:
"object invoked disconnected from client"

UGH !


--------------------------------------------------------------------------------
"Tom Ogilvy" wrote in message ...
? "msgbox""You done it"",vbOKOnly"
msgbox"You done it",vbOKOnly

do you just need some spaces?

--
Regards,
Tom Ogilvy

"mark kubicki" wrote in message
...
i'm trying to add code to give function to a newly created command button

on
the form "frmTimeClock"
but, am not quite getting it right... (?)

the error occurs at line 7 (57017, event handler is invalid)

----------------------------------------------
1 Private Sub CommandButton1_Click()
2 Dim StartLineNum As Long
3 Dim mycmd As MSForms.CommandButton

4 Set mycmd = frmTimeClock.Controls.Add("forms.commandbutton.1")
5 mycmd.Caption = mycmd.Name

6 With ActiveWorkbook.VBProject.VBComponents("frmTimeCloc k").CodeModule
7 StartLineNum = .CreateEventProc("click", mycmd.Name) + 1
8 .InsertLines StartLineNum, _
9 "msgbox""You done it"",vbOKOnly"
10 End With

11 End Sub
------------------------------------------------


thanks (as always) in advance
mark