Closed Thread
Results 1 to 7 of 7

Event handler is invalid

  1. #1
    Minh
    Guest

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


  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Minh,

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

    Sincerely,
    Leith Ross

  3. #3
    Minh
    Guest

    Re: Event handler is invalid

    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
    >
    >


  4. #4
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Maybe?

    Do not all dim statements need to be at the beginning of the routine?
    Thanks!
    Dennis

    I am using Windows 7 and Office 2007, all of my posts are based on this.

  5. #5
    Norman Jones
    Guest

    Re: Event handler is invalid

    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
    news:[email protected]...
    >
    > Do not all dim statements need to be at the beginning of the routine?
    >
    >
    > --
    > DCSwearingen
    >
    >
    > ------------------------------------------------------------------------
    > DCSwearingen's Profile:
    > http://www.excelforum.com/member.php...o&userid=21506
    > View this thread: http://www.excelforum.com/showthread...hreadid=491149
    >




  6. #6
    Bob Phillips
    Guest

    Re: Event handler is invalid

    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" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    > >
    > >




  7. #7
    Minh
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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
    > > >
    > > >

    >
    >
    >


Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1