JAD said:
*How do I add existing multiple macro routines within a
single macro? Any help would be appreciated. Thank You, JAD *
Hi there!
This is one of those "easy" subjects that is only easy once you lear
it.
What I mean is, I think you will find it VERY easy to run a macro *fro
within another macro* once you learn the correct syntax.
But for anyone who doesn't know the syntax, it of course seems like a
obscure, far-off dream.
I'm attaching a zipped xls file as a demonstration. Anyone intereste
should dowload the file (Macro_in_a_macro.xls.zip) and unzip it an
play around with it.
Additionally, here is the complete code from the xls file. Paste al
this code into one module, and then run the first macro to observe ho
it calls on all the other macros.
Code
-------------------
Sub Master_Macro_to_call_others()
Dim myName As String
Dim aTime
myName = "Me"
MsgBox "At the start of all this, my name is: " & myName
Say_Hi
Announce_FileName
Change_Original_Name myName
MsgBox "Now my name is: " & myName
aTime = WhatTime()
MsgBox aTime
End Sub
Sub Say_Hi()
MsgBox "Hi!", , "Message from the second macro"
End Sub
Sub Announce_FileName()
MsgBox "Active book is: " & ActiveWorkbook.Name, , "The third macro says:"
End Sub
Sub Change_Original_Name(aName As String)
aName = "Big Blue River"
End Sub
Function WhatTime()
WhatTime = VBA.Now
End Function
-------------------
The above example may seem like "silly" code, and in some senses it is
However, I did indeed choose each little macro for a reason.
the "Sub Change_Original_Name" macro demonstrates how the master macr
can PASS A VARIABLE to another macro. The "Change" macro changes th
value of the variable, and then the original "Master" macro display
the new value.
Also, the FUNCTION "WhatTime" demonstrates that if you write a functio
that contains within itself a VARIABLE with the SAME name as th
function, then you can access the value of that variable by calling th
function, which is what the "Master" macro does on the line that says:
aTime = WhatTime()
It is all much clearer if you copy the code or download the file an
try it out.
Best of luck!
-Kelly
____________________________
http://kellyjones.netfirms.com/visualbasic/search_in_folders.htm
Attachment filename: macro_in_a_macro.xls.zip
Download attachment:
http://www.excelforum.com/attachment.php?postid=61791