![]() |
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 |
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 |
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 |
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 |
Run or Call
Thanks Tom & Jim,
The replies were aa great help and I'll make the code changes tonight. Mickey |
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 |
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 |
Run or Call
Thanks Chip,
Advice much appreciated, Mickey |
All times are GMT +1. The time now is 07:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com