Hi breadwinner,
Try the attached file.
Lewis
Code follows:
Option Explicit
Sub ProcessXlsbFiles()
Dim sPath As String
Dim sPathAndFileName As String
Dim sFileName As String
Dim iCount As Long
Dim iRow As Long
'Clear the output range
ThisWorkbook.Sheets("Sheet1").Rows("21:65000").Clear
'Get the folder name
sPath = Trim(ThisWorkbook.Sheets("Sheet1").Range("D3").Text)
If Len(sPath) = 0 Then
Debug.Print "There is no Folder Name specified in 'Sheet1' Cell 'D3'."
End If
'Make sure the path has a trailing backslash
If Right(sPath, 1) <> "\" Then
sPath = sPath & "\"
End If
'Define the row before the first output row number
iRow = 20
'Create the path and file name for the first file find
sPathAndFileName = sPath & "*.xlsb"
'Find the first file
sFileName = Dir(sPathAndFileName)
'Loop until all matching files have been found
While Len(sFileName) > 0
'Debug.Print sPath & sFileName
'Increment the found file count
iCount = iCount + 1
'Output a message
iRow = iRow + 1
ThisWorkbook.Sheets("Sheet1").Cells(iRow, 1) = _
iCount & " Processing file - " & sFileName
'Scroll down so the user can follow progress
ActiveWindow.SmallScroll Down:=1
'Process the next file
Call ProcessOneFile(sPath & sFileName)
'Search for the next matching file
sFileName = Dir()
Wend
If iCount = 0 Then
iRow = iRow + 1
ThisWorkbook.Sheets("Sheet1").Cells(iRow, 1) = "There were NO .xlsb files to process."
End If
End Sub
Function ProcessOneFile(sPathAndFileName As String) As Long
Dim ws As Worksheet
On Error GoTo ERROR_EXIT:
'Open the file
Workbooks.Open FileName:=sPathAndFileName
'Set the worksheet object
Set ws = ActiveWorkbook.Sheets("OPencall")
'Turn AutoFilter Off on the specified sheet
ws.Cells.AutoFilter
'Unhide all columns in the specified sheet
ws.Cells.EntireColumn.Hidden = False
'Save the file and inhibit 'Do you really want to messages'
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=True
Application.DisplayAlerts = True
Exit Function
ERROR_EXIT:
'Set failure error return
ProcessOneFile = 1
ActiveWorkbook.Close SaveChanges:=False
End Function
Bookmarks