Run/Call module in multiple Workbooks.

lashings1986

New Member
Joined
Jul 25, 2017
Messages
6
I am trying to run a macro in a workbook that opens other workbooks in a file and runs all the vba in Module2 of each specific workbook.

Module2 is different in each of the workbooks

This is the code i am using. It runs through each of the workbooks perfectly I just need it to run the Module2 vba from each workbook. Tried using call function also but doesn't seem to work.

it is the line in bold

Any help would be great.

Sub BatchProcessing()
myPath = "C:\Users\bloomberg\Desktop\updated Morning update models VBA TESTS v2"
MyTemplate = "*.xls*" ' Set the template.
MyName = Dir(myPath & MyTemplate) 'Retrieve the first file
Do While MyName <> ""
Workbooks.Open myPath & MyName
Application.run (module2.updateflagship)
Workbooks(MyName).Close 'close
MyName = Dir 'Get next file
Loop
End Sub



Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this:
Code:
Sub BatchProcessing()
    myPath = "C:\Users\bloomberg\Desktop\updated Morning update models VBA TESTS v2"
    MyTemplate = "*.xls*" ' Set the template.
    MyName = Dir(myPath & MyTemplate) 'Retrieve the first file
    Do While MyName <> ""
        Application.Run "'" & myPath & MyTemplate & "'!Module2.updateflagship"
        Workbooks(MyName).Close 'close
        MyName = Dir 'Get next file
    Loop
End Sub
 
Upvote 0
Thanks for your response.

I tried your code.

I received a run time error '1004' "the macro not be available in the workbook or all macros may be disabled"

any ideas?

thanks very much
 
Upvote 0
Have you added a "" at the end of the Path ?
Code:
[COLOR=#333333] Application.Run "'" & myPath & [/COLOR][COLOR=#ff0000][B]"\"[/B][/COLOR][COLOR=#333333] &  MyTemplate & "'!Module2.updateflagship"[/COLOR]
 
Last edited:
Upvote 0
tried it with the "" inserted but still no luck.

the path is in " "

it looks like this now

Sub BatchProcessing()
myPath = "C:\Users\bloomberg\Desktop\updated Morning update models VBA TESTS v2"
MyTemplate = "*.xls*" ' Set the template.
MyName = Dir(myPath & MyTemplate) 'Retrieve the first file
Do While MyName <> ""
Application.run "'" & myPath & "/" & MyTemplate & "'!Module2.updateflagship"
Workbooks(MyName).Close 'close
MyName = Dir 'Get next file
Loop
End Sub


thanks for the help
 
Upvote 0
should be like this with a slash:
Code:
[COLOR=#333333][COLOR=#333333] Application.Run "'" & myPath & [/COLOR][/COLOR][COLOR=#ff0000][B]"\"[/B][/COLOR][COLOR=#333333][COLOR=#333333] &  MyTemplate & "'!Module2.updateflagship"[/COLOR][/COLOR]
Not with a forward slash

If that still doesn't work then are you sure the Macro name is correct as well as the host module in each workbook that you are opening ?
 
Last edited:
Upvote 0
tried it with the \ still no good.

I just checked the first workbook that the code opens and Module2 when opens contains the following on the first line:

sub UPDATEFLAGSHIP ()

this should be fine shouldn't it? the code should find this?

it is falling down on this first workbook and kicking me out of excel.

Very annoying when i have done so much work to get to the point of just opening and running all the code ive built.

thanks again.
 
Upvote 0
Try opening only one workbook (forget the Do While for now) and see what you get .

Also, try it with the workbook already open.
 
Upvote 0
I tried without the Do while and the loop and also with the file open. neither worked i got the same error.

I replaced the run module2 code with a simple workbook.save and it ran through all the files perfectly. So it is something on that line of code that it does not like. Is it possible to link directly to the macro and not the module? or the module and not the macro?
 
Upvote 0
I think, you should be able to omit the word Module2 .. like this :
Code:
[COLOR=#333333][COLOR=#333333] Application.Run "'" & myPath & [/COLOR][/COLOR][COLOR=#ff0000][B]"\"[/B][/COLOR][COLOR=#333333][COLOR=#333333] &  MyTemplate & "'!updateflagship"[/COLOR][/COLOR]

I'll be leaving shortly so I hope someone will jump in to help you if you have still not solved the problem.

Good luck.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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