Reputation: 51
My code is:
Dim wb As Workbook
Dim MyObj As Object, MySource As Object, file As Variant
file = Dir("C:\Users\dlf164\Desktop\NE\")
While (file <> "")
If InStr(file, a) > 0 Then
Set wb = Workbooks.Open(file)
End If
file = Dir
Wend
The error which I am receiving is Application or object defined runtime error.
How to solve this?
Upvotes: 2
Views: 4733
Reputation: 22185
Dir()
only returns the filename, but Workbooks.Open()
requires the full path. Try something like this:
Dim wb As Workbook
Dim MyObj As Object, MySource As Object, file As Variant
Dim path As String
path = "C:\Users\dlf164\Desktop\NE\"
file = Dir(path)
While (file <> "")
If InStr(file, a) > 0 Then
Set wb = Workbooks.Open(path & file)
End If
file = Dir
Wend
Upvotes: 4