View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
davegb davegb is offline
external usenet poster
 
Posts: 573
Default 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.