Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling Code From Sheets (XL97:SR2)

    I have code in an XL object of a project which I want to activate by clicking on a button by using the following code:

    Private Sub CommandButton1_Click()
    Call Start
    End Sub

    Unfortunately I receive "Sub or Function not defined". It is defined (the best I can determine...in Sheet 3). Any assistance would be appreciated.

    Thanks,
    John

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling Code From Sheets (XL97:SR2)

    Where is the command button, on a User Form or on a Worksheet?

    In any event, code called from a button click event routine should be in a General module, not in the module behind a worksheet.
    Legare Coleman

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling Code From Sheets (XL97:SR2)

    If Start is in the same project as the Sheet, the Start has to be a Public Sub in a regular module.

    If Start is in a different Project than the sheet, Start still has to be a Public Sub, but yu might be able to use

    Application.Run Start

    Or something of that ilk.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Calling Code From Sheets (XL97:SR2)

    As Legare suggests, the procedure is best placed in a general module. However if the code is in the Sheet3 codepane, you could use
    <pre>Private Sub CommandButton1_Click()
    Call Sheet3.Start
    End Sub</pre>

    provided that Start is not defined as a Private Sub.

    Andrew C

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling Code From Sheets (XL97:SR2)

    The code was behind a sheet not in a general module and the button was in a userform. The "Call Sheet3.Start" worked.

    Thanks,
    John

Posting Permissions

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