Open files from folder by matching name
Hi Again
First off sorry my first code didn't work for you, not sure why as i
tested it and it runs fine for me with the info from your post? Anywho
i can't think of a way around it using your proposed method however i
have come up with a sort of combo of the two, this time without the
FSO but still using the InStr function as i think this is the easiest
way to check for a name in a string...
I have added a few escape routes to try and get out of the loops to
prevent unnecessary cycles, let me know how you get on with the code
and of course if you find a way around the problem :)
Dim fldrName As String
Dim fName
Dim lastcl As Integer
Dim i As Integer
Dim intFound As Integer
Sub test()
fldrName = "C:\Record"
fName = Dir(fldrName & "\*.xls")
With Workbooks("Data.xls")
lastcl = .Sheets("Sheet1").Cells _
(Rows.Count, "A").End(xlUp).Row
Do While fName < ""
For i = 1 To lastcl
If InStr(1, fName, .ActiveSheet.Cells(i, 1).Value, _
vbTextCompare) < 0 Then
Workbooks.Open (fldrName & "\" & fName)
intFound = intFound + 1
i = lastcl
End If
Next i
fName = Dir()
If intFound = lastcl Then Exit Do
Loop
End With
End Sub
Steve
|