Option Explicit
Sub Macro2()
Dim objFSO As Object
Dim objFolder As Object
Dim objSubfolder As Object
Dim objFile As Object
Dim clnQueue As Collection
Dim strPath As String
Dim wb As Workbook
Dim ws As Worksheet
Application.ScreenUpdating = False
strPath = "Z:\Thirumoorthy\test\" 'Directory path containing Excel files. Change to suit.
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set clnQueue = New Collection
clnQueue.Add objFSO.GetFolder(strPath)
Do While clnQueue.Count > 0
Set objFolder = clnQueue(1)
clnQueue.Remove 1
For Each objSubfolder In objFolder.SubFolders
clnQueue.Add objSubfolder
Next objSubfolder
For Each objFile In objFolder.Files
If InStr(objFSO.GetExtensionName(objFile.Name), "xls") > 0 Then
Set wb = Workbooks.Open(objFolder.Path & "\" & objFile.Name)
For Each ws In wb.Worksheets
ws.Activate
'Your code here
Next ws
wb.Close SaveChanges:=True
Set wb = Nothing
End If
Next objFile
Loop
Application.ScreenUpdating = True
End Sub