VBA code to open multiple files in same folder and perform same macros
Sub OpenAndClearContentsInColumnAA()
Dim strF As String, strP As String
Dim wb As Workbook
Dim ws As Worksheet
'Edit this declaration to your folder name
strP = "C:\Documents and Settings\MANAGER\Desktop\Dazzas Files" 'change for the path of your folder
strF = Dir(strP & "\*.xlsm") 'Change as required
Do While strF <> vbNullString
Set wb = Workbooks.Open(strP & "\" & strF)
Set ws = wb.Sheets(1) 'uses first sheet or if all the same names then ws.Sheets("yoursheet")
ws.Range("AA2:AA" & ws.Range("AA" & ws.Rows.Count).End(xlUp).Row).ClearContents
wb.Close True
strF = Dir()
Loop
End Sub
and another VBA Code To Open Multiple Excel Files;
Const FOLDER As String = "C:\\test\"
Sub ProcessEachFileInFolder()
On Error Goto ErrorHandler
Dim fileName As String
fileName = Dir(FOLDER, vbDirectory)
' loop through folder, only process .xls files
Do While Len(fileName) > 0
If Right$(fileName, 4) = "xlsb" Then
Call ProcessFile(fileName)
End If
fileName = Dir
Loop
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Sub ProcessFile(fileName As String)
Dim currentWkbk As Excel.Workbook
' open workbook
Set currentWkbk = Excel.Workbooks.Open(FOLDER & fileName)
' do whatever you need to do with currentWkbk
End Sub
Bookmarks