Here is a example for delete and add a sub
Delete it first and add a new one
You can use this for events also
Sub AddProcedure()
Dim VBCodeMod As CodeModule
Dim LineNum As Long
Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("Sheet1").Code Module
With VBCodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, _
"Sub MyNewProcedure()" & Chr(13) & _
" Msgbox ""Here is the new procedure"" " & Chr(13) & _
"End Sub"
End With
End Sub
Sub DeleteProcedure()
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long
Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("Sheet1").Code Module
With VBCodeMod
StartLine = .ProcStartLine("MyNewProcedure", vbext_pk_Proc)
HowManyLines = .ProcCountLines("MyNewProcedure", vbext_pk_Proc)
.DeleteLines StartLine, HowManyLines
End With
End Sub
--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl
"Haldun Alay" <haldunalayATyahooDOTcom wrote in message ...
Hi Ron,
Thanks for your reply.
I try the codes on the site that you adviced but the problem is still exist.
For example I have a textbox control : TextBox1 and it's event sub
TextBox1_Enter() already defined.
Also I have one sub called AssignThis() in userform's code. What I want to
do is, While running userform, in some conditions I want to change
TextBox1's OnEnter event's sub to AssignThis via versa. On that site it
shows how to add events whose are not exist.
--
Regards
Haldun Alay
To e-mail me, please remove AT and DOT from my e-mail address.
"Ron de Bruin" , iletide şunu yazdı
...
Check out Chip Pearson's site
http://www.cpearson.com/excel/vbe.htm
--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl
"Haldun Alay" <haldunalayATyahooDOTcom wrote in message
...
Hi,
I'm designing a userform with several controls (Textboxes, Comboboxes,
CommandButtons etc.). But I create some controls on air via code. I want
to
assign some subs ON AIR to control's event procs like On Enter, On
Change,
On Exit... Does anybody know how can I do that? Thanks in advance...
--
Regards
Haldun Alay
To e-mail me, please remove AT and DOT from my e-mail address.