#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Run or Call

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

Mickey




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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" wrote in message
...
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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default 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" wrote in message
...
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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Run or Call

Thanks Chip,
Advice much appreciated,

Mickey


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wouldn't know what to call it! 1Fish2Fish Excel Worksheet Functions 5 August 26th 08 07:37 PM
Call Center Management: How to calculate 'cost per call' Denniso6 Excel Discussion (Misc queries) 2 June 25th 06 05:01 PM
call sub mike allen[_2_] Excel Programming 3 October 15th 04 04:54 PM
How do you call one Sub from another Sub ? lothario[_30_] Excel Programming 2 October 17th 03 01:47 PM
call sub Claudia Dell'Era[_2_] Excel Programming 3 October 3rd 03 01:31 PM


All times are GMT +1. The time now is 07:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"