I am pasting a part of one of my macros , the macro below works:
Dim wb As Workbook
Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet, ws5 As Worksheet, ws6 As Worksheet, ws7 As Worksheet, wsFiles As Worksheet
Dim strPath As String, strMsg As String, lMsgType As Long
Dim cell As Range
Dim RowNdx As Long
Set wsFiles = ThisWorkbook.Sheets("Look_UpTable") ' Worksheet with file list
Set ws7 = ThisWorkbook.Sheets("Dummy1")
strPath = "C:\MyFolder\AfterFeb2011\New\My-Tool\" ' Folder of the data files'
Application.ScreenUpdating = False
For Each cell In ws7.Range("D1", ws7.Range("D" & Rows.Count).End(xlUp))
On Error Resume Next
' Attempt to open the next file
Set wb = Application.Workbooks.Open(strPath & cell.value)
On Error GoTo 0
If Not wb Is Nothing Then 'if the file was opened
..................................
..................................
The macro below(as per your suggestion) does not work:
Dim wb As Workbook
Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet, ws5 As Worksheet, ws6 As Worksheet, ws7 As Worksheet, wsFiles As Worksheet
Dim strPath As String, strMsg As String, lMsgType As Long
Dim cell As Range
Dim RowNdx As Long
strPath = ActiveWorkbook.Path
Set wsFiles = ThisWorkbook.Sheets("Look_UpTable") ' Worksheet with file list
Set ws7 = ThisWorkbook.Sheets("Dummy1")
Application.ScreenUpdating = False
For Each cell In ws7.Range("D1", ws7.Range("D" & Rows.Count).End(xlUp))
On Error Resume Next
' Attempt to open the next file
Set wb = Application.Workbooks.Open(strPath & cell.value)
On Error GoTo 0
If Not wb Is Nothing Then 'if the file was opened
..................................
..................................