Consulting

Results 1 to 8 of 8

Thread: Solved: Calling a Subroutine

  1. #1

    Solved: Calling a Subroutine

    Hi

    Yet another question, basically lets say I have several exit buttons throughout my program, I create a little sub in a module which contains the coding.

    Now could I have a small piece of coding which would link to the sub within the Module and execute it?

    Thanks

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    [VBA]
    Sub a()
    name of the little sub in a module which contains the coding(one word)
    end sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Yep, except I might suggest you use "CALL subname" to remind you that it's a macro and not a variable. It helps the self documentation objective.
    Sid

  4. #4
    Hi

    That works for form based buttons, however i was wondering if something can be used for buttons on UserForms?

    Quote Originally Posted by lucas
    [vba]
    Sub a()
    name of the little sub in a module which contains the coding(one word)
    end sub
    [/vba]

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    hi bobo...pretty basic stuff here...read your help files some ok?
    [VBA]Private Sub CommandButton1_Click()
    name of the little Sub In a module which contains the coding(one word)
    End Sub[/VBA]
    Sid is right too...probably a good idea to use call then the name of the macro
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    In that case, the name of the sub-routine you're calling might be something like:

    [vba]
    cmdImport_Click
    [/vba]

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    click is the key...Hi Anne
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Hiya Steve!

Posting Permissions

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