+ Reply to Thread
Results 1 to 8 of 8

Run or Call

  1. #1
    MBlake
    Guest

    Run or Call

    Hi,
    I'd appreciate some advice on when to use Run and when to use Call within
    vba. For example in Sheet1 the following code works fine and all the
    intended macros run when the relevant CommandButtons are pressed. However I
    need to understand when to use the Call statement and when to use Run. All
    I know at present is that use of Run requires "" and Call does not.

    Thanks,
    Mickey

    Option Explicit

    Private Sub cbo28Day_Click()
    Call sort28
    End Sub

    Private Sub cboCritical_Click()
    Call sortCritical
    End Sub

    Private Sub cboEnterData_Click()
    Run "formNew"
    End Sub



  2. #2
    Tom Ogilvy
    Guest

    Re: Run or Call

    Always use call or just use the name of the macro. This should work for all
    macros contained in the same workbook. If you need to use a macro in an
    addin or in another open workbook, then you would use run. (unless you
    created a reference to that workbook/addin, and then you could use call. )
    Call is faster.

    --
    Regards,
    Tom Ogilvy





    "MBlake" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    > I'd appreciate some advice on when to use Run and when to use Call within
    > vba. For example in Sheet1 the following code works fine and all the
    > intended macros run when the relevant CommandButtons are pressed. However

    I
    > need to understand when to use the Call statement and when to use Run.

    All
    > I know at present is that use of Run requires "" and Call does not.
    >
    > Thanks,
    > Mickey
    >
    > Option Explicit
    >
    > Private Sub cbo28Day_Click()
    > Call sort28
    > End Sub
    >
    > Private Sub cboCritical_Click()
    > Call sortCritical
    > End Sub
    >
    > Private Sub cboEnterData_Click()
    > Run "formNew"
    > End Sub
    >
    >




  3. #3
    Jim Thomlinson
    Guest

    RE: Run or Call

    Sticking with the key word "Call" (I personally neve use run) the use of it
    is optional. As a matter of readability I normally include it whenever I
    refer to a procedure that I have coded in my project. That way I know that it
    refers to a procedure that I wrote and is not a key work in VBA. I find that
    it makes things a little more clear and readable. Additionally when you use
    Call then the arguments of the procedure must be enclosed in brackets which I
    find makes the code a little more readable. But it is entirely optional.
    However you choose to do it just be consistent... IMO

    --
    HTH...

    Jim Thomlinson


    "MBlake" wrote:

    > Hi,
    > I'd appreciate some advice on when to use Run and when to use Call within
    > vba. For example in Sheet1 the following code works fine and all the
    > intended macros run when the relevant CommandButtons are pressed. However I
    > need to understand when to use the Call statement and when to use Run. All
    > I know at present is that use of Run requires "" and Call does not.
    >
    > Thanks,
    > Mickey
    >
    > Option Explicit
    >
    > Private Sub cbo28Day_Click()
    > Call sort28
    > End Sub
    >
    > Private Sub cboCritical_Click()
    > Call sortCritical
    > End Sub
    >
    > Private Sub cboEnterData_Click()
    > Run "formNew"
    > End Sub
    >
    >
    >


  4. #4
    Jim Thomlinson
    Guest

    Re: Run or Call

    Is it faster to create a reference to the addin and then use call or would it
    be faster to use run? I use the reference thing as I have just never liked
    run but if run would be more efficient...
    --
    HTH...

    Jim Thomlinson


    "Tom Ogilvy" wrote:

    > Always use call or just use the name of the macro. This should work for all
    > macros contained in the same workbook. If you need to use a macro in an
    > addin or in another open workbook, then you would use run. (unless you
    > created a reference to that workbook/addin, and then you could use call. )
    > Call is faster.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    >
    >
    > "MBlake" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi,
    > > I'd appreciate some advice on when to use Run and when to use Call within
    > > vba. For example in Sheet1 the following code works fine and all the
    > > intended macros run when the relevant CommandButtons are pressed. However

    > I
    > > need to understand when to use the Call statement and when to use Run.

    > All
    > > I know at present is that use of Run requires "" and Call does not.
    > >
    > > Thanks,
    > > Mickey
    > >
    > > Option Explicit
    > >
    > > Private Sub cbo28Day_Click()
    > > Call sort28
    > > End Sub
    > >
    > > Private Sub cboCritical_Click()
    > > Call sortCritical
    > > End Sub
    > >
    > > Private Sub cboEnterData_Click()
    > > Run "formNew"
    > > End Sub
    > >
    > >

    >
    >
    >


  5. #5
    MBlake
    Guest

    Re: Run or Call

    Thanks Tom & Jim,
    The replies were aa great help and I'll make the code changes tonight.

    Mickey



  6. #6
    Chip Pearson
    Guest

    Re: Run or Call

    Run is considerably less efficient. First it must find the
    workbook, the search the VBA for the specified macro to determine
    whether it exists, and then determine what arguments it takes and
    what type the return value (if any) is. All this is done at run
    time. With Call, all that is done at compile time.


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "Jim Thomlinson" <[email protected]> wrote in message
    news:[email protected]...
    > Is it faster to create a reference to the addin and then use
    > call or would it
    > be faster to use run? I use the reference thing as I have just
    > never liked
    > run but if run would be more efficient...
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "Tom Ogilvy" wrote:
    >
    >> Always use call or just use the name of the macro. This
    >> should work for all
    >> macros contained in the same workbook. If you need to use a
    >> macro in an
    >> addin or in another open workbook, then you would use run.
    >> (unless you
    >> created a reference to that workbook/addin, and then you could
    >> use call. )
    >> Call is faster.
    >>
    >> --
    >> Regards,
    >> Tom Ogilvy
    >>
    >>
    >>
    >>
    >>
    >> "MBlake" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > Hi,
    >> > I'd appreciate some advice on when to use Run and when to
    >> > use Call within
    >> > vba. For example in Sheet1 the following code works fine
    >> > and all the
    >> > intended macros run when the relevant CommandButtons are
    >> > pressed. However

    >> I
    >> > need to understand when to use the Call statement and when
    >> > to use Run.

    >> All
    >> > I know at present is that use of Run requires "" and Call
    >> > does not.
    >> >
    >> > Thanks,
    >> > Mickey
    >> >
    >> > Option Explicit
    >> >
    >> > Private Sub cbo28Day_Click()
    >> > Call sort28
    >> > End Sub
    >> >
    >> > Private Sub cboCritical_Click()
    >> > Call sortCritical
    >> > End Sub
    >> >
    >> > Private Sub cboEnterData_Click()
    >> > Run "formNew"
    >> > End Sub
    >> >
    >> >

    >>
    >>
    >>




  7. #7
    Jim Thomlinson
    Guest

    Re: Run or Call

    As always you are a veritable wealth of useful information...

    Thanks

    Jim Thomlinson


    "Chip Pearson" wrote:

    > Run is considerably less efficient. First it must find the
    > workbook, the search the VBA for the specified macro to determine
    > whether it exists, and then determine what arguments it takes and
    > what type the return value (if any) is. All this is done at run
    > time. With Call, all that is done at compile time.
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    > "Jim Thomlinson" <[email protected]> wrote in message
    > news:[email protected]...
    > > Is it faster to create a reference to the addin and then use
    > > call or would it
    > > be faster to use run? I use the reference thing as I have just
    > > never liked
    > > run but if run would be more efficient...
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Tom Ogilvy" wrote:
    > >
    > >> Always use call or just use the name of the macro. This
    > >> should work for all
    > >> macros contained in the same workbook. If you need to use a
    > >> macro in an
    > >> addin or in another open workbook, then you would use run.
    > >> (unless you
    > >> created a reference to that workbook/addin, and then you could
    > >> use call. )
    > >> Call is faster.
    > >>
    > >> --
    > >> Regards,
    > >> Tom Ogilvy
    > >>
    > >>
    > >>
    > >>
    > >>
    > >> "MBlake" <[email protected]> wrote in message
    > >> news:[email protected]...
    > >> > Hi,
    > >> > I'd appreciate some advice on when to use Run and when to
    > >> > use Call within
    > >> > vba. For example in Sheet1 the following code works fine
    > >> > and all the
    > >> > intended macros run when the relevant CommandButtons are
    > >> > pressed. However
    > >> I
    > >> > need to understand when to use the Call statement and when
    > >> > to use Run.
    > >> All
    > >> > I know at present is that use of Run requires "" and Call
    > >> > does not.
    > >> >
    > >> > Thanks,
    > >> > Mickey
    > >> >
    > >> > Option Explicit
    > >> >
    > >> > Private Sub cbo28Day_Click()
    > >> > Call sort28
    > >> > End Sub
    > >> >
    > >> > Private Sub cboCritical_Click()
    > >> > Call sortCritical
    > >> > End Sub
    > >> >
    > >> > Private Sub cboEnterData_Click()
    > >> > Run "formNew"
    > >> > End Sub
    > >> >
    > >> >
    > >>
    > >>
    > >>

    >
    >
    >


  8. #8
    MBlake
    Guest

    Re: Run or Call

    Thanks Chip,
    Advice much appreciated,

    Mickey



+ Reply to 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