How to run a macro at same time across multiple workbook files?
This article, I will talk about how to run a macro across multiple workbook files at the same time without opening them. The following method can help you to solve this task in Excel.
To run a macro across multiple workbooks without opening them, please apply the following VBA code:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following macro in the Module Window.
VBA code: Run the same macro on multiple workbooks at same time:
Sub LoopThroughFiles() Dim xFd As FileDialog Dim xFdItem As Variant Dim xFileName As String Set xFd = Application.FileDialog(msoFileDialogFolderPicker) If xFd.Show = -1 Then xFdItem = xFd.SelectedItems(1) & Application.PathSeparator xFileName = Dir(xFdItem & "*.xls*") Do While xFileName <> "" With Workbooks.Open(xFdItem & xFileName) 'your code here End With xFileName = Dir Loop End If End Sub
Note: In the above code, please copy and paste your own code without the Sub heading and End Sub footer between the With Workbooks.Open(xFdItem & xFileName) and End With scripts. See screenshot:
3. Then press F5 key to execute this code, and a Browse window is displayed, please select a folder which contains the workbooks that you want to all apply this macro, see screenshot:
4. And then click OK button, the desired macro will be executed at once from one workbook to others.
Best Office Productivity Tools
Supports Office/Excel 2007-2021 and 365 | Available in 44 Languages | Easy to Uninstall Completely
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...
Supercharge Your Excel Skills: Experience Efficiency Like Never Before with Kutools for Excel (Full-Featured 30-Day Free Trial)
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day! (Full-Featured 30-Day Free Trial)