Solved

executing macros from all files in a folder

Posted on 2016-10-04
5
51 Views
Last Modified: 2016-10-04
I have a folder with multiple files with a macro in each file. How can I execute all the macros in all the files one after other setting up a time gap say of 15 minutes.

all the files has the same macro.

Thanks in advance!!!
0
Comment
Question by:Nirvana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

Expert Comment

by:Norie
ID: 41828390
What's the name of the macro and where is it located?
0
 

Author Comment

by:Nirvana
ID: 41828482
I have used below code  and used the actual code, however, it is not working. infact, i need to press a button in each file how can Click the button on each file

Private Sub CommandButton1_Click()
    Module1.dakin
End Sub

Sub LoopThroughDirectory()
Application.DisplayAlerts = False
'Change this to your directory
MyPath = "C:\Users\Desktop\"
activefile = Dir(MyPath & "*.xls")
Do While activefile <> ""
   Workbooks.Open Filename:=MyPath & activefile
   'Here is the line that calls the macro below, passing the workbook to it
   DoSomething ActiveWorkbook
   ActiveWorkbook.Save
   ActiveWorkbook.Close
   activefile = Dir()
Loop
Application.DisplayAlerts = True
End Sub

Open in new window

0
 
LVL 34

Accepted Solution

by:
Norie earned 500 total points
ID: 41828568
That button appears to be calling a sub named 'dakin' which is in Module1.

If that's the case there's no need to click the button, we can call the sub directly.
Sub LoopThroughDirectory()
Dim wb As Workbook
Dim MyPath As String
Dim activefile As String

    Application.DisplayAlerts = False
    'Change this to your directory
    MyPath = "C:\Users\Desktop\"
    activefile = Dir(MyPath & "*.xls")
    Do While activefile <> ""
        Set wb = Workbooks.Open(Filename:=MyPath & activefile)
        'Here is the line that calls the macro below, passing the workbook to it
        With wb
            Application.Run "'" & wb.Name & "'!dakin"


            .Close SaveChanges:=True
        End With

        activefile = Dir()
    Loop
    
    Application.DisplayAlerts = True
    
End Sub

Open in new window

1
 

Author Closing Comment

by:Nirvana
ID: 41828680
Brilliant
0
 

Author Comment

by:Nirvana
ID: 41828685
Thanks, Norie.. works perfectly!!!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question