how to force a macro in excel to start another macro?

Associate
Joined
18 Oct 2002
Posts
2,333
Location
London, WC1
Hey all,

I'm having a bit of trouble with excel. I need to record a macro that will first initiate a few other macros (which sit in the spreadsheet as buttons), and then do some of it's own functions.

any ideas how to force excel macros to start other macros? I can't figure it out and google seems to yeild nothing!!

Thanks loads!

IZoneIZ
 
izoneiz,

This is very simple to accomplish.

I will assume you have knowledge of the VBA editor within excel. (if not, let me know and I will ellaborate).

Each macro you record actually creates a VBA sub procedure with the same name. What you would need to do is create your container macro (lets just call it macro1) and then edit it within VBA.

As it stands, it will read along the following lines: -

Code:
Sub macro1()

macro1 code here

End Sub

Lets say you have two other macros called macro2 and macro3 (original huh?)

You would amend your macro1 code to read as follows:-

Code:
Sub macro1()

macro2() 'Execute code in macro2
macro3() ' Execute code in macro3

macro1 code here

End Sub

Hope this helps, if you need more explaining, let me know.

Ta

Naqi
 
Naqi said:
izoneiz,

This is very simple to accomplish.

I will assume you have knowledge of the VBA editor within excel. (if not, let me know and I will ellaborate).

Each macro you record actually creates a VBA sub procedure with the same name. What you would need to do is create your container macro (lets just call it macro1) and then edit it within VBA.

As it stands, it will read along the following lines: -

Code:
Sub macro1()

macro1 code here

End Sub

Lets say you have two other macros called macro2 and macro3 (original huh?)

You would amend your macro1 code to read as follows:-

Code:
Sub macro1()

macro2() 'Execute code in macro2
macro3() ' Execute code in macro3

macro1 code here

End Sub

Hope this helps, if you need more explaining, let me know.

Ta

Naqi

Naqi,

Thanks for the info.

It doesn't seem to work. I'm familiar with the VBA editor, and have tried commands such as "run" and "call", and have now tried what you suggested (simply just have a line that reads macro2() ), but that seems to come up with a syntax compiling error. Any ideas?

Thanks

IZoneIZ
 
izoneiz,

What is the exact text of the error message you are getting?

Are you able to email the S/S so I can play with it?

Naqi
 
Actually,

Homer moment, dont put the brackets in after calling the first two macros ala:-

Code:
Sub macro1()

macro2 'Execute code in macro2
macro3 ' Execute code in macro3

macro1 code here

End Sub

Ive just tried a simple S/S with three macros in this manner and it works.

Naqi
 
Naqi said:
Actually,

Homer moment, dont put the brackets in after calling the first two macros ala:-

Code:
Sub macro1()

macro2 'Execute code in macro2
macro3 ' Execute code in macro3

macro1 code here

End Sub

Ive just tried a simple S/S with three macros in this manner and it works.

Naqi

You Sir, are a genius.

It works!!!!!

I was certain I had tried that before, but seemingly not!!!!

Many thanks - I've spent a few hours trying to make this work (VBA n00b)!

IZoneIZ
 
Back
Top Bottom