ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Event handler is invalid (https://www.excelbanter.com/excel-programming/347467-event-handler-invalid.html)

Minh[_2_]

Event handler is invalid
 
Hello! Any ideas why I am getting this error?

I did add the Extensibility reference, and set Trust access to Visual Basic
Project. I also started over in a new workbook to make sure any previous
error did not corrupt anything.

Dim myLabel As MSForms.Label
Set myLabel = myForm.Controls.Add("Forms.Label.1", "Label1")

Dim myLine As Long

With ActiveWorkbook.VBProject.VBComponents("myForm").Co deModule
myLine = .CreateEventProc("Click", myLabel.Name) + 1
.InsertLines myLine, "MsgBox ""Hello!"""
End With


Leith Ross[_353_]

Event handler is invalid
 

Hello Minh,

Change *Dim myLine As Long* to *Dim myLine*. You are getting an error
because you are trying to assign a non nimeric value to a Long
Integer.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=491149


Minh[_2_]

Event handler is invalid
 
Thanks, Bob! Any help would be greatly appreciated!

Minh

"Bob Phillips" wrote:

I don't think that was the problem. The data type should be long as it
returns the line number. The problem seems to be that the control is not
known at that point. I'll see if I can make time to have a play today.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Minh" wrote in message
...
Hi Leith!

I appreciate the reply. However, I am still getting the error after I
modify the Dim statement. Any help would be appreciated.

Thanks!
minh

"Leith Ross" wrote:


Hello Minh,

Change *Dim myLine As Long* to *Dim myLine*. You are getting an error
because you are trying to assign a non nimeric value to a Long
Integer.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:

http://www.excelforum.com/member.php...o&userid=18465
View this thread:

http://www.excelforum.com/showthread...hreadid=491149







All times are GMT +1. The time now is 08:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com