Help needed - Button to clear multiple workbooks

Valleymatt

New Member
Joined
May 8, 2017
Messages
1
Hi guys, hoping you can help on my first post.

I have about 20 different workbooks (one for each staff member) and they each complete confidential data on these every day. The data then feeds in to a master sheet that only I can see. I have added a button to each individual workbook so that it clears all unlocked cells of data and can be re-used the following day. However, I can only clear the workbooks when I'm satisfied that I have gathered all the required information. I then have to go in to each workbook, enable the macro, clear the data, save and exit. This can be very time consuming. Is it possible to add a button to the master sheet that will 'trigger' the clear data button on all the other workbooks? Any help would be greatly appreciated. Thanks.
VM
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Valleymatt,

Welcome to the Board.

The construct for calling a macro in another workbook (assuming the other workbook is open) is:

Code:
Application.Run "MacroBook!MacroName"

So essentially you need a loop to open each of the 20 workbooks, call its macro, close the workbook, and repeat with the next workbook.

Cheers,

tonyyy
 
Upvote 0
.
.
Code:
Option Explicit


Sub LoopAllExcelFilesInFolder()
'PURPOSE: To loop through all Excel files in a user specified folder and perform a set task on them
'SOURCE: www.TheSpreadsheetGuru.com


Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog


'Optimize Macro Speed
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  Application.Calculation = xlCalculationManual


'Retrieve Target Folder Path From User
  Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)


    With FldrPicker
      .Title = "Select A Target Folder"
      .AllowMultiSelect = False
        If .Show <> -1 Then GoTo NextCode
        myPath = .SelectedItems(1) & "\"
    End With


'In Case of Cancel
NextCode:
  myPath = myPath
  If myPath = "" Then GoTo ResetSettings


'Target File Extension (must include wildcard "*")
  myExtension = "*.xls*"


'Target Path with Ending Extention
  myFile = Dir(myPath & myExtension)


'Loop through each Excel file in folder
  Do While myFile <> ""
    'Set variable equal to opened workbook
      Set wb = Workbooks.Open(Filename:=myPath & myFile)
    
    'Ensure Workbook has opened before moving on to next line of code
      DoEvents


'////////////////////////////////////////////////////////////////////////////
    
    '-->    Place your macro here to run the macro in the other workbooks.          <---
    '-->    Probably best that the macro would be named the same thing in each      <---
    '-->    of the other workbooks to simplify the coding here.                     <---
    
'////////////////////////////////////////////////////////////////////////////
    'Save and Close Workbook
      wb.Close SaveChanges:=True
      
    'Ensure Workbook has closed before moving on to next line of code
      DoEvents


    'Get next file name
      myFile = Dir
  Loop


'Message Box when tasks are completed
  MsgBox "Task Complete!"


ResetSettings:
  'Reset Macro Optimization Settings
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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