Event handler is invalid

G

Guest

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").CodeModule
myLine = .CreateEventProc("Click", myLabel.Name) + 1
.InsertLines myLine, "MsgBox ""Hello!"""
End With
 
L

Leith Ross

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
 
G

Guest

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
 
N

Norman Jones

Hi DC,
Do not all dim statements need to be at the beginning of the routine?

No. Variables may be dimensioned at any point prior to use. Indeed, in the
inadvisable absence of the Option Explicit statement, variables need not be
explicitly dimmed at all. In the latter case, of course, such variables will
be implicitly dimmed..

---
Regards,
Norman



"DCSwearingen" <[email protected]>
wrote in message
 
B

Bob Phillips

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top