Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Event procedures for controls added with CreateEventProc

I need to create event procedures for controls added with Controls.Add.
The following approach was suggested:

Private Sub UserForm_Activate()
Dim Ct As Control, StartLine as long

Set Ct = Me.Controls.Add("Forms.TextBox.1", "txtNew" , True)
With ActiveWorkbook.VBProject.VBComponents("UserForm1") .CodeModule
StartLine = .CreateEventProc("Change", Ct.Name) + 1
.... add the text for the procedure..

But I get a runtime error on the .CreateEventProc call - Error 57017 "Event
handler is invalid"

Where have I gone wrong? Are there any other approaches (such as control
arrays in VB6)

Another complication is that when the workbook is protected, the line:
With ActiveWorkbook.VBProject.VBComponents("UserForm1") .CodeModule
causes a run-time error. I really need to trap the TextBox change events
with the VBA code protected.

Many thanks,
--
John Austin

--
John Austin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Event procedures for controls added with CreateEventProc

Hi

I can reproduce the problem, and now I am researching the issue, and I will
update you ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Event procedures for controls added with CreateEventProc

Hi

Based on my research, because the VBA code will be compiled and you are
trying to add a component to the currently running and compiled UserForm,
therefore your object is not yet included when the code is compiled and you
get the error.
So far I think you should be creating all of your controls on the UserForm
in design time just like VB, you can hide any you don't want visible.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Event procedures for controls added with CreateEventProc

I need one text box for each worksheet (variable) in the workbook. Is it
possible to use API calls to hook the Text_changed event for the control to
some existing sub, perhaps passing a handle to the control that raised the
event?

""Peter Huang" [MSFT]" wrote:

Hi

Based on my research, because the VBA code will be compiled and you are
trying to add a component to the currently running and compiled UserForm,
therefore your object is not yet included when the code is compiled and you
get the error.
So far I think you should be creating all of your controls on the UserForm
in design time just like VB, you can hide any you don't want visible.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Event procedures for controls added with CreateEventProc

Hi

I am sorry I may have some confusion about your scenario.
Because the UserForm is included in the workbook but not the worksheet, I
assume here you want to add the button onto the Worksheet but not the
userform.
If so, I think you may try to take a look at the link below.
How To Add a Button to a Word Document and Assign Its Click Event at
Run-time
http://support.microsoft.com/?id=246299

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Event procedures for controls added with CreateEventProc

Hi Peter,
No, everything is on the UserForm. It is simply the number of TextBoxes that
I need to add to the UserForm that is related to the number of sheets in the
workbook.

John

""Peter Huang" [MSFT]" wrote:

Hi

I am sorry I may have some confusion about your scenario.
Because the UserForm is included in the workbook but not the worksheet, I
assume here you want to add the button onto the Worksheet but not the
userform.
If so, I think you may try to take a look at the link below.
How To Add a Button to a Word Document and Assign Its Click Event at
Run-time
http://support.microsoft.com/?id=246299

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply
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 procedures for controls added with CreateEventProc John Austin[_5_] Excel Programming 0 March 12th 05 09:33 PM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM
learning event procedures R.VENKATARAMAN Excel Programming 4 January 21st 05 01:09 PM
Event Procedures: Event on Worksheet to fire Event on another Worksheet Kathryn Excel Programming 2 April 7th 04 07:35 PM
Creating Event procedures from a macro Robert Stober Excel Programming 3 September 7th 03 06:52 PM


All times are GMT +1. The time now is 04:48 AM.

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"