Run to all excel files in a folder

Abegail0203

New Member
Joined
Mar 6, 2022
Messages
13
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I have a macro that runs only in a sheet. I want your assistance to have the macro to run on all files in a folder.

This is my current macro:

Sub yellow()

Range("a1:z500").Select
For Each Cell In Selection
If Cell.Interior.Color = Excel.XlRgbColor.rgbYellow Then
Cell.Clear
End If
Next
End Sub


The macro will remove/clear all values in a cell highlighted in yellow.
I would like to run a macro that will do it for all the files in a specific folder in one single click.

Thank you.
 
Add this macro:
VBA Code:
Public Sub All_Workbooks_In_Folder()
    folder = "C:\path\to\folder\"  ' <--------- CHANGE THIS
    file = Dir(folder & "*.xlsx")
    While file <> vbNullString
        Workbooks.Open folder & file
        yellow
        ActiveWorkbook.Close True
        file = Dir
    Wend
    MsgBox "Done"
End Sub
 
Upvote 0
Add this macro:
VBA Code:
Public Sub All_Workbooks_In_Folder()
    folder = "C:\path\to\folder\"  ' <--------- CHANGE THIS
    file = Dir(folder & "*.xlsx")
    While file <> vbNullString
        Workbooks.Open folder & file
        yellow
        ActiveWorkbook.Close True
        file = Dir
    Wend
    MsgBox "Done"
End Sub
Thanks!
 
Upvote 0

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