LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Using A Macro To Add Event Procedure To A CommandButton

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Procedure Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:29 PM
Event Procedure again Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:28 PM
programming the VBE for a new event procedure mark kubicki Excel Programming 3 August 18th 04 04:43 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"