Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Dynamic Control addition and Event response

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Soenen - 22 Jan 2006 16:45 GMT
I dynamically added a CommandButton using the ADD method as shown below. Now
the problem is:  How do I define?,create?,handle? the click event that is
generated by that control. I have tried putting in event handlers named:

Private Sub CommandButton1_Click()
Private Sub Zbut_Click()
Private Sub ZButton_Click()

and none work.

Thanks,
ken

Dim ZButton As Control
Set ZButton = Controls.Add("Forms.CommandButton.1", "ZBut")
With ZButton
   .left = 17
   .top = 30
   .Width = 12
   .Height = 12
   .BackColor = &H8000000F
   .ForeColor = &H80000012
   .Caption = "Z"
   .FontSize = 10
   .Font.Bold = True
End With
Dave Peterson - 22 Jan 2006 17:19 GMT
Chip Pearson has some instructions on writing code that writes code at:
http://cpearson.com/excel/vbe.htm

> I dynamically added a CommandButton using the ADD method as shown below. Now
> the problem is:  How do I define?,create?,handle? the click event that is
[quoted text clipped - 22 lines]
>     .Font.Bold = True
> End With

Signature

Dave Peterson

Ken Soenen - 22 Jan 2006 19:26 GMT
Thanks Dave.  I tried Chip's "code creation stuff" but the problem still is
selecting the "NAME"  XXXX that would be placed in front of the "_Click()"
in the event handler declaration. Like: Private Sub XXXX_Click().

ken

> Chip Pearson has some instructions on writing code that writes code at:
> http://cpearson.com/excel/vbe.htm
[quoted text clipped - 26 lines]
>>     .Font.Bold = True
>> End With
Dave Peterson - 22 Jan 2006 19:55 GMT
A little search of Google will show you lots of samples.

http://groups.google.co.uk/group/microsoft.public.excel.programming/browse_frm/t
hread/e279799b2b1e163e/6465b0e85e2c7312?lnk=st&q=.CreateEventProc(+group%3A*exce
l*&rnum=14&hl=en#6465b0e85e2c7312


or

http://snipurl.com/ltxq

> Thanks Dave.  I tried Chip's "code creation stuff" but the problem still is
> selecting the "NAME"  XXXX that would be placed in front of the "_Click()"
[quoted text clipped - 36 lines]
> >
> > Dave Peterson

Signature

Dave Peterson

Ken Soenen - 23 Jan 2006 00:06 GMT
Thanks for your help Dave.
ken
>A little search of Google will show you lots of samples.
>
[quoted text clipped - 49 lines]
>> >
>> > Dave Peterson
Tom Ogilvy - 22 Jan 2006 20:42 GMT
Not sure why you are adding a control with code - I would bet there is a
simpler way to accomplish what you need.  Nonetheless, you might look at
John Walkenbach's sample:

http://www.j-walk.com/ss/excel/tips/tip76.htm

Signature

Regards,
Tom Ogilvy

> Thanks Dave.  I tried Chip's "code creation stuff" but the problem still is
> selecting the "NAME"  XXXX that would be placed in front of the "_Click()"
[quoted text clipped - 32 lines]
> >>     .Font.Bold = True
> >> End With
Ken Soenen - 23 Jan 2006 00:07 GMT
Thanks Tom.

ken
> Not sure why you are adding a control with code - I would bet there is a
> simpler way to accomplish what you need.  Nonetheless, you might look at
[quoted text clipped - 43 lines]
>> >>     .Font.Bold = True
>> >> End With
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.