ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I refer to other macros inside a macro code? (https://www.excelbanter.com/excel-programming/335538-how-do-i-refer-other-macros-inside-macro-code.html)

Erkka

How do I refer to other macros inside a macro code?
 
Is it possible to run other macros from inside a macro code? I ask this
because I would like to keep the code entities as simple as possible and
therefore not to make them too long by adding all the code in one macro and
then typing the same code in other places where it is needed.

Mayank Prakash Gupta

How do I refer to other macros inside a macro code?
 
use "call <macro name"
it should work

hth
MPG
"Erkka" wrote in message
...
Is it possible to run other macros from inside a macro code? I ask this
because I would like to keep the code entities as simple as possible and
therefore not to make them too long by adding all the code in one macro
and
then typing the same code in other places where it is needed.




Bob Phillips[_7_]

How do I refer to other macros inside a macro code?
 
Sub Macro1()

'do some stuff
Call Macro2
'do seom more

End SUb

Sub Macro2()

'do some macro2 stuff

Enbd Sub

--
HTH

Bob Phillips

"Erkka" wrote in message
...
Is it possible to run other macros from inside a macro code? I ask this
because I would like to keep the code entities as simple as possible and
therefore not to make them too long by adding all the code in one macro

and
then typing the same code in other places where it is needed.




davegb

How do I refer to other macros inside a macro code?
 


Erkka wrote:
Is it possible to run other macros from inside a macro code? I ask this
because I would like to keep the code entities as simple as possible and
therefore not to make them too long by adding all the code in one macro and
then typing the same code in other places where it is needed.


This is "a", if not "the", way to do it. In Walkenbach he talks about
writing shorter macros, then stitching them together. It works for me.
It keeps the amount of code I'm working on at any one time small and
easier to debug. And it "modularizes" the code. Once I have code that
say, finds a value and then does something to modify the column that
value is in, I can reuse it in other programs where I need something
similiar. It's also useful for some kinds of programs that I use
stand-alone and in other code. I.e., I work with a lot of data
downloaded data from a program called SPSS, a statistics program. The
downloaded files are "dirty" to XL. Lot's of invisible "stuff" in both
empty cells and cells with data in them that can cause problems working
in XL. I found a program online that removes the "dirt" from these
files. In some cases, I just run my macro "Clean" to remove the nasty
stuff. I also have a program that reformats certain kinds of these
downloaded files to be used in another spreadsheet. I have a macro that
runs the "Clean" macro first, then reformats the sheet. So "Clean" can
be a standalone macro when I need it, and called by another macro when
it's just part of a larger process.
I think it's definitely a good idea to modularize this way. Keep in
mind, I'm still new to VBA programming, so maybe there are
disadvantages I haven't seen yet. Some of the more experienced people
here can probably help us both with that aspect of this issue.
Hope this helps in your world.



All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com