Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Folkes,
I know there are plenty of question/discussions relating to this but I am not understanding. I have a commandbutton1 on a sheet which I copy and paste using a macro resulting in a commandbutton2. I then want to use the macro to write the event code for commandbutton2. The event code I want is:- Private Sub CommandButton2_Click() d = Range("E1") Call Common End Sub I have a copy of www.cpearson.com - Programming To The VBE but I am not understanding what I have to do to write the code. I have :- Dim StartLine As Long With ActiveWorkbook.VBProject.VBComponents(ActiveSheet) .CodeModule StartLine = .CreateEventProc("Click", "CommandButton2") .InsertLines StartLine, "d = Range(""E1"")" & Chr(13) & "Call Common" End With which I know is wrong but have no understanding of what is right or wrong. Can any of you wizards out there help me out. Cheers |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Doing so with one of these, Donna you should fix your problem Private Sub CommandButton1_Click() Dim StartLine As Long With ActiveWorkbook.VBProject.VBComponents(ActiveSheet. CodeName).CodeModule StartLine = .CreateEventProc("Click", "CommandButton2") .InsertLines .ProcBodyLine("CommandButton2_Click", vbext_pk_Proc) + 1, "d = Range(""E1"")" & Chr(13) & "Call Common " End With End Sub OR Private Sub CommandButton1_Click() Dim StartLine As Long With ActiveWorkbook.VBProject.VBComponents(ActiveSheet. CodeName).CodeModule StartLine = .CreateEventProc("Click", "CommandButton2") .InsertLines StartLine + 1, "d = Range(""E1"")" & Chr(13) & "Call Common " End With End Sub So long, Donna a écrit : Folkes, I know there are plenty of question/discussions relating to this but I am not understanding. I have a commandbutton1 on a sheet which I copy and paste using a macro resulting in a commandbutton2. I then want to use the macro to write the event code for commandbutton2. The event code I want is:- Private Sub CommandButton2_Click() d = Range("E1") Call Common End Sub I have a copy of www.cpearson.com - Programming To The VBE but I am not understanding what I have to do to write the code. I have :- Dim StartLine As Long With ActiveWorkbook.VBProject.VBComponents(ActiveSheet) .CodeModule StartLine = .CreateEventProc("Click", "CommandButton2") .InsertLines StartLine, "d = Range(""E1"")" & Chr(13) & "Call Common" End With which I know is wrong but have no understanding of what is right or wrong. Can any of you wizards out there help me out. Cheers |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Event Procedure | Excel Programming | |||
Event Procedure again | Excel Programming | |||
programming the VBE for a new event procedure | Excel Programming | |||
OnTime event not firing in Workbook_Open event procedure | Excel Programming |