![]() |
Macro Running Another Macro
Hi,
Put all your macro names in a seperate sub and call them sequentially Sub RunEmAll() Mymacro1 Mymacro2 Mymacro3 Mymacro4 'etc End Sub Mike On Thu, 22 Jan 2009 11:35:01 -0800, Mark P wrote: Is it possible to create a macro that just runs a few other macros? I have 12 separate macros with separate shortcuts and it'd be easier to have one shortcut. Thanks! |
Macro Running Another Macro
Is it possible to create a macro that just runs a few other macros? I have 12
separate macros with separate shortcuts and it'd be easier to have one shortcut. Thanks! |
Macro Running Another Macro
sub Mark()
call MarkFormatting call MarkCopying call MarkPrinting End Sub you can call as many as you want from the main macro, and they can be contained in other modules. hope that helps! :) susan On Jan 22, 2:35*pm, Mark P wrote: Is it possible to create a macro that just runs a few other macros? I have 12 separate macros with separate shortcuts and it'd be easier to have one shortcut. Thanks! |
Macro Running Another Macro
Sub Demo()
Call Hello End Sub Sub Hello() Msgbox("Hello") End Sub -- Gary''s Student - gsnu200828 "Mark P" wrote: Is it possible to create a macro that just runs a few other macros? I have 12 separate macros with separate shortcuts and it'd be easier to have one shortcut. Thanks! |
Macro Running Another Macro
Actually, you don't even have to use the "Call" keyword as it's assumed in
VBA. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Susan" wrote in message ... sub Mark() call MarkFormatting call MarkCopying call MarkPrinting End Sub you can call as many as you want from the main macro, and they can be contained in other modules. hope that helps! :) susan On Jan 22, 2:35 pm, Mark P wrote: Is it possible to create a macro that just runs a few other macros? I have 12 separate macros with separate shortcuts and it'd be easier to have one shortcut. Thanks! |
Macro Running Another Macro
Ronald - personal choice, i guess - i hate not using "call" because
then in the code you've got this "MarkFormatting" text hanging out there all alone with no indication of what it is or what it's doing. yes i may remember today what it is, but six months from now? by using the "call" keyword i'm reminding myself of what "MarkFormatting" is and what it's doing. like i said, personal choice, but technically you're right. :) susan On Jan 22, 2:44*pm, "Ronald R. Dodge, Jr." wrote: Actually, you don't even have to use the "Call" keyword as it's assumed in VBA. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000"Susan" wrote in message ... sub Mark() call MarkFormatting call MarkCopying call MarkPrinting End Sub you can call as many as you want from the main macro, and they can be contained in other modules. hope that helps! :) susan On Jan 22, 2:35 pm, Mark P wrote: Is it possible to create a macro that just runs a few other macros? I have 12 separate macros with separate shortcuts and it'd be easier to have one shortcut. Thanks!- Hide quoted text - - Show quoted text - |
Macro Running Another Macro
I'm with Susan on this, code is unreadable without Call.
And it gets a lot worse when passing variables to code: DoSomethingUseful X, MyString, MyCell, strWarningText vs Call DoSomethingUseful (X, MyString, MyCell, strWarningText) Best wishes Harald "Ronald R. Dodge, Jr." skrev i melding ... Actually, you don't even have to use the "Call" keyword as it's assumed in VBA. |
Macro Running Another Macro
Even though I do remember the old BASIC days, within VBA, every line starts
with a keyword except for maybe called on procedures or letting simple data types equal to some value (Yes, this includes properties and arrays that use simple data types). For those statement lines that's not starting with key words (at least within my VBA, marked as cyan color), then it's obviously a call to something or an expression setting/letting (Set keyword must be used for objects, but Let keyword is understood for simple data types) to some object/value respectively. For you, I guess you use the Call keyword to distinguish what methods are being called on. Do you also use the Let keyword to distinguish which lines are letting simple data types equal to some value? Now as far as how I do it, since I like to keep my stuff as short as reasonably possible, but still want readability for debugging and modification purposes, I use method and variable naming schemes, so as I know what is what. The following as just a sample list. l_str (This indicates to me that this is a string variable within the procedure) l, m, and g for that first letter with variable names. Different 3 letter codes for different variable types. prp for properties pcd for methods setup as a procedure fnc for methods setup as a function ro on properties with only Get statement wo on properties with only Let/Set statement rw on properties with both Get and Let/Set statements. prp_<type of property code_<PropertyName like: prp_rw_Value for a property with the Value name that is both read and write. so in my case, if I was to setup the call, it would be like pcdMarkFormatting '(If this is a call to a Sub) OR fncMarkFormatting '(If this is a call to a Function) Of course, I realize many of us have different things, but the same basic idea to achieve the same basic deal. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Susan" wrote in message ... Ronald - personal choice, i guess - i hate not using "call" because then in the code you've got this "MarkFormatting" text hanging out there all alone with no indication of what it is or what it's doing. yes i may remember today what it is, but six months from now? by using the "call" keyword i'm reminding myself of what "MarkFormatting" is and what it's doing. like i said, personal choice, but technically you're right. :) susan On Jan 22, 2:44 pm, "Ronald R. Dodge, Jr." wrote: Actually, you don't even have to use the "Call" keyword as it's assumed in VBA. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000"Susan" wrote in message ... sub Mark() call MarkFormatting call MarkCopying call MarkPrinting End Sub you can call as many as you want from the main macro, and they can be contained in other modules. hope that helps! :) susan On Jan 22, 2:35 pm, Mark P wrote: Is it possible to create a macro that just runs a few other macros? I have 12 separate macros with separate shortcuts and it'd be easier to have one shortcut. Thanks!- Hide quoted text - - Show quoted text - |
Macro Running Another Macro
What sort of issues have you had without using the Call keyword? I been
doing it without the Call keyword from the start of me using VBA back in 1998 and never once have I had a problem without using the Call keyword. The only thing I see based on how you using the 2 lines below, the first line is calling up the command as if it's being used as a "Sub" call (Rather if the method is a Sub or Function) vs. the second one is being used as a "Function" call (The method is a Function). How can I tell? First call (implied), you don't use the parenthesizes and the second call, you do. Sub calls, you can only use without the parenthesizes vs. Function calls, you can use the parenthesizes, but don't have to. However, that depends if you are using the method as a function to return something (Use the parenthesizes) or if you are using it as a sub just to execute something (Don't use the parenthesizes). However, if you do use the parenthesizes, you must have it either equal to something (via either Let [in many cases, you see this left off too, but can be used] or Set) or have it in an argument that will take the value/object of what the function returns. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Harald Staff" wrote in message ... I'm with Susan on this, code is unreadable without Call. And it gets a lot worse when passing variables to code: DoSomethingUseful X, MyString, MyCell, strWarningText vs Call DoSomethingUseful (X, MyString, MyCell, strWarningText) Best wishes Harald "Ronald R. Dodge, Jr." skrev i melding ... Actually, you don't even have to use the "Call" keyword as it's assumed in VBA. |
Macro Running Another Macro
Hi Ronald
As stated, this is only about making the code readable and self explaining. I hate writing code documentation. You are not right about sub and function calls. Try this: Sub test() Dim S As String ' sub calls: MessageMe "First message", 1 Call MessageMe("Second message", 2) 'function calls: MsgBox SheSaid("Watch this") S = SheSaid("And this") MsgBox S Call SheSaid("You won't see this") MsgBox SheSaid "This errs" S = SheSaid "This too" MsgBox S End Sub Sub MessageMe(strMsg As String, LCounter As Long) MsgBox strMsg & vbNewLine & vbNewLine & _ "This is example number " & LCounter End Sub Function SheSaid(strMsg As String) As String SheSaid = "The lady said: " & strMsg End Function A sub is just a function returning nothing (Void), so from a code point of view the difference is very little. Best wishes Harald "Ronald R. Dodge, Jr." wrote in message ... What sort of issues have you had without using the Call keyword? I been doing it without the Call keyword from the start of me using VBA back in 1998 and never once have I had a problem without using the Call keyword. The only thing I see based on how you using the 2 lines below, the first line is calling up the command as if it's being used as a "Sub" call (Rather if the method is a Sub or Function) vs. the second one is being used as a "Function" call (The method is a Function). How can I tell? First call (implied), you don't use the parenthesizes and the second call, you do. Sub calls, you can only use without the parenthesizes vs. Function calls, you can use the parenthesizes, but don't have to. However, that depends if you are using the method as a function to return something (Use the parenthesizes) or if you are using it as a sub just to execute something (Don't use the parenthesizes). However, if you do use the parenthesizes, you must have it either equal to something (via either Let [in many cases, you see this left off too, but can be used] or Set) or have it in an argument that will take the value/object of what the function returns. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Harald Staff" wrote in message ... I'm with Susan on this, code is unreadable without Call. And it gets a lot worse when passing variables to code: DoSomethingUseful X, MyString, MyCell, strWarningText vs Call DoSomethingUseful (X, MyString, MyCell, strWarningText) Best wishes Harald "Ronald R. Dodge, Jr." skrev i melding ... Actually, you don't even have to use the "Call" keyword as it's assumed in VBA. |
Macro Running Another Macro
With just one argument, VBA does let you get away with using the
parenthesizes. However, it puts a space between the method name and the opening parenthesis. Okay, so with the Call statement, you do have to use parenthesizes as I didn't realize that without looking in the help file, so you got me on that one. However, without the Call keyword, if attempt to use a function as a Sub with the parenthesizes that involves more than 1 argument, it will give you a syntax error. As for what you are implying with the "SheSaid" function, you are saying that you can't use Functions as Subs, which if that is the case, you are incorrect there as well. Functions can be setup either to return values or to perform executions and return a value to indicate what ever it's intended to indicate. In the latter case, the developer that uses the function can then either use it as a sub or as a function (normally for error trapping purposes, but can be for other purposes as well such as the MsgBox function can be used either as a sub [for simple information for the user] or a function [for the user to choose which way to go, which then the code continues with which ever direction based on which button the user activated]). As for the line: S = SheSaid "This too" What are you attempting to say here? Of course you can't use a function as a sub in this manner. For that case, you can't use a Sub in this manner either as a Sub doesn't return anything. And this line below as well: MsgBox SheSaid "This errs" Again, this is an obvious syntax issue as there's too many issues with it. I'm not going to get into the list of issues as that can get to be rather lengthy. As for this line below of yours MessageMe "First message", 1 Yes, you can use a function like this. You are using like a sub as you are not using the value it returns. It may return the value, but it's not being assigned to anything so it's value is almost instantly forgotten. As for the line below: Call SheSaid("You won't see this") You are attempting to say you can't use this as a Sub. With this use of a Function of course not cause it doesn't perform any sort of action outside of assignments. If you are using a Function that performs other actions, and returns a Boolean value to indicate rather if it was successful or not (Just one example of how something like that could be setup), then the developer can either use it like a sub and ignore the result from the function or like an actual function call taking into account of the result from the function. On the other hand, if you are attempting to use this as a function, then it's an improper syntax for that. Out of all the lines of code you have provided, you still haven't provided a good reason why one must use a Call statement. On the other hand, if one is using it just as a preference, no problem there as we each have our own systems, what we are familiar with and use to. I don't know if you misinterpreted my statements about Subs and Functions, but the only thing I was incorrect on initially was in regards to the parenthesizes on a Call statement for sub use. I admit I haven't used the Call statement, but I have used and still do use Subs and Functions quite extensively including in classes just as I do with many of the other key components. If I didn't know how to use Subs and Functions by now, I wouldn't be nearly as far along as I am. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Harald Staff" wrote in message ... Hi Ronald As stated, this is only about making the code readable and self explaining. I hate writing code documentation. You are not right about sub and function calls. Try this: Sub test() Dim S As String ' sub calls: MessageMe "First message", 1 Call MessageMe("Second message", 2) 'function calls: MsgBox SheSaid("Watch this") S = SheSaid("And this") MsgBox S Call SheSaid("You won't see this") MsgBox SheSaid "This errs" S = SheSaid "This too" MsgBox S End Sub Sub MessageMe(strMsg As String, LCounter As Long) MsgBox strMsg & vbNewLine & vbNewLine & _ "This is example number " & LCounter End Sub Function SheSaid(strMsg As String) As String SheSaid = "The lady said: " & strMsg End Function A sub is just a function returning nothing (Void), so from a code point of view the difference is very little. Best wishes Harald "Ronald R. Dodge, Jr." wrote in message ... What sort of issues have you had without using the Call keyword? I been doing it without the Call keyword from the start of me using VBA back in 1998 and never once have I had a problem without using the Call keyword. The only thing I see based on how you using the 2 lines below, the first line is calling up the command as if it's being used as a "Sub" call (Rather if the method is a Sub or Function) vs. the second one is being used as a "Function" call (The method is a Function). How can I tell? First call (implied), you don't use the parenthesizes and the second call, you do. Sub calls, you can only use without the parenthesizes vs. Function calls, you can use the parenthesizes, but don't have to. However, that depends if you are using the method as a function to return something (Use the parenthesizes) or if you are using it as a sub just to execute something (Don't use the parenthesizes). However, if you do use the parenthesizes, you must have it either equal to something (via either Let [in many cases, you see this left off too, but can be used] or Set) or have it in an argument that will take the value/object of what the function returns. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Harald Staff" wrote in message ... I'm with Susan on this, code is unreadable without Call. And it gets a lot worse when passing variables to code: DoSomethingUseful X, MyString, MyCell, strWarningText vs Call DoSomethingUseful (X, MyString, MyCell, strWarningText) Best wishes Harald "Ronald R. Dodge, Jr." skrev i melding ... Actually, you don't even have to use the "Call" keyword as it's assumed in VBA. |
Macro Running Another Macro
With all respect sir, it is unusually difficult and also a tiny bit
unpleasant to communicate with you. This ends now. Best wishes Harald "Ronald R. Dodge, Jr." wrote in message ... With just one argument, VBA does let you get away with using the parenthesizes. However, it puts a space between the method name and the opening parenthesis. Okay, so with the Call statement, you do have to use parenthesizes as I didn't realize that without looking in the help file, so you got me on that one. However, without the Call keyword, if attempt to use a function as a Sub with the parenthesizes that involves more than 1 argument, it will give you a syntax error. As for what you are implying with the "SheSaid" function, you are saying that you can't use Functions as Subs, which if that is the case, you are incorrect there as well. Functions can be setup either to return values or to perform executions and return a value to indicate what ever it's intended to indicate. In the latter case, the developer that uses the function can then either use it as a sub or as a function (normally for error trapping purposes, but can be for other purposes as well such as the MsgBox function can be used either as a sub [for simple information for the user] or a function [for the user to choose which way to go, which then the code continues with which ever direction based on which button the user activated]). As for the line: S = SheSaid "This too" What are you attempting to say here? Of course you can't use a function as a sub in this manner. For that case, you can't use a Sub in this manner either as a Sub doesn't return anything. And this line below as well: MsgBox SheSaid "This errs" Again, this is an obvious syntax issue as there's too many issues with it. I'm not going to get into the list of issues as that can get to be rather lengthy. As for this line below of yours MessageMe "First message", 1 Yes, you can use a function like this. You are using like a sub as you are not using the value it returns. It may return the value, but it's not being assigned to anything so it's value is almost instantly forgotten. As for the line below: Call SheSaid("You won't see this") You are attempting to say you can't use this as a Sub. With this use of a Function of course not cause it doesn't perform any sort of action outside of assignments. If you are using a Function that performs other actions, and returns a Boolean value to indicate rather if it was successful or not (Just one example of how something like that could be setup), then the developer can either use it like a sub and ignore the result from the function or like an actual function call taking into account of the result from the function. On the other hand, if you are attempting to use this as a function, then it's an improper syntax for that. Out of all the lines of code you have provided, you still haven't provided a good reason why one must use a Call statement. On the other hand, if one is using it just as a preference, no problem there as we each have our own systems, what we are familiar with and use to. I don't know if you misinterpreted my statements about Subs and Functions, but the only thing I was incorrect on initially was in regards to the parenthesizes on a Call statement for sub use. I admit I haven't used the Call statement, but I have used and still do use Subs and Functions quite extensively including in classes just as I do with many of the other key components. If I didn't know how to use Subs and Functions by now, I wouldn't be nearly as far along as I am. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Harald Staff" wrote in message ... Hi Ronald As stated, this is only about making the code readable and self explaining. I hate writing code documentation. You are not right about sub and function calls. Try this: Sub test() Dim S As String ' sub calls: MessageMe "First message", 1 Call MessageMe("Second message", 2) 'function calls: MsgBox SheSaid("Watch this") S = SheSaid("And this") MsgBox S Call SheSaid("You won't see this") MsgBox SheSaid "This errs" S = SheSaid "This too" MsgBox S End Sub Sub MessageMe(strMsg As String, LCounter As Long) MsgBox strMsg & vbNewLine & vbNewLine & _ "This is example number " & LCounter End Sub Function SheSaid(strMsg As String) As String SheSaid = "The lady said: " & strMsg End Function A sub is just a function returning nothing (Void), so from a code point of view the difference is very little. Best wishes Harald "Ronald R. Dodge, Jr." wrote in message ... What sort of issues have you had without using the Call keyword? I been doing it without the Call keyword from the start of me using VBA back in 1998 and never once have I had a problem without using the Call keyword. The only thing I see based on how you using the 2 lines below, the first line is calling up the command as if it's being used as a "Sub" call (Rather if the method is a Sub or Function) vs. the second one is being used as a "Function" call (The method is a Function). How can I tell? First call (implied), you don't use the parenthesizes and the second call, you do. Sub calls, you can only use without the parenthesizes vs. Function calls, you can use the parenthesizes, but don't have to. However, that depends if you are using the method as a function to return something (Use the parenthesizes) or if you are using it as a sub just to execute something (Don't use the parenthesizes). However, if you do use the parenthesizes, you must have it either equal to something (via either Let [in many cases, you see this left off too, but can be used] or Set) or have it in an argument that will take the value/object of what the function returns. -- Thanks, Ronald R. Dodge, Jr. Production Statistician Master MOUS 2000 "Harald Staff" wrote in message ... I'm with Susan on this, code is unreadable without Call. And it gets a lot worse when passing variables to code: DoSomethingUseful X, MyString, MyCell, strWarningText vs Call DoSomethingUseful (X, MyString, MyCell, strWarningText) Best wishes Harald "Ronald R. Dodge, Jr." skrev i melding ... Actually, you don't even have to use the "Call" keyword as it's assumed in VBA. |
All times are GMT +1. The time now is 04:09 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com