Call one macro from another

L

Legacy 96851

Guest
I have a macro called Extract that opens all the files in a directory (and does other stuff with them). My second macro (named Divide) needs to be run on each of these files before Extract can be run. Is there a way I can make Extract call Divide on each file after it opens it?

Thanks.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Yes, you can call Divide from Extract. Just add either:
Code:
Divide
or
Code:
Call Divide
to your Extract code in the relevant location (assuming both macros are in the same workbook)
 
Upvote 0
Yes.

Call your Divide macro from your Extract macro after each file is opened in Extract. Whether this will work does depend on how each is coded, but you have yet to provide your existing code, so it is difficult to comment on this point.

Code:
'to call one macro from another:
 
Sub Message()
MsgBox "Hello"
End Sub
 
Sub Test()
Message
End Sub

In the above, if you run Test, it calls Message.
 
Upvote 0
I didn't post my source code because it is rather long and didn't seem relevant. If it would help, I will, but the code is pages long, so that seems ridiculous.

When I put this in my code
Code:
Set sourcewb = Workbooks.Open(myPath & sumfile)
Call Divide
I get an error saying "Compile error: Expected variable or procedure, not module"
 
Upvote 0
Did you name your module Divide?
 
Upvote 0
Do you also have any variables named Divide as well as a subprocedure? This can confuse VBA (in which case you should name your variables to something else).
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,484
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top