I simplified the macros wrote two versions.One using Dir() and another with the 
FileSystem object.
they both work just fine:
Sub First_Macro()
    Dim MyFile As String
    Dim path As String
    
    path = "D:\For Pankaj\Dump\"
    MyFile = Dir(path & "*L1.xlsx")
    
    Do While MyFile <> ""
        Workbooks.Open (path & MyFile)
        MyFile = Dir()
    Loop
End SubSub fSys_Macro()
    Dim f, fldr, fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fldr = fso.getfolder("D:\For Pankaj\Dump")
    For Each f In fldr.Files
        If (InStr(1, f.Name, "L1") > 0) Then Workbooks.Open f.path
    Next f
End Sub
 Paul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
----------------------------------------- 

    On Wednesday, April 27, 2016 4:05 PM, Secret Shot <secrets...@gmail.com> 
wrote:
 
 

 Dear Experts,
I want to open all files in a folder with suffix of "L1", where i have below 
files in a folder
04 L1.Xlsx04 L2.Xlsx05 L1.Xlsx05 L2.Xlsx06 L1.Xlsx06 L2.Xlsx

I want macro to open Only files which contain "L1", (Means 04 L1.Xlsx, 05 
L1.Xlsx, 06 L1.Xlsx).
I created 2 macros but both giving me same error "Run-time error '1004': Sorry, 
we couldn't find 05 L1.Xlsx. It is possible it was moved, renamed or deleted?"
Both macro are opening first file (I mean 04 L1.Xlsx) perfectly, but giving 
error on second file.
Below are the macro's 
Sub First_Macro()      Dim MyFile As String      Dim path As String        path 
= "D:\For Pankaj\Dump\"        MyFile = Dir(path & "*.xlsx")         Do While 
MyFile <> ""                If InStr(MyFile, "L1") > 0 Then                
MsgBox path & "\" & MyFile                Workbooks.Open (MyFile)        End If 
       MyFile = Dir()        Loop   End Sub 
Sub Second_Macro()Dim path As StringDim Fname As StringDim p As String
path = "D:\For Pankaj\Dump\"Fname = ".xlsx"p = "*L1"   MyFile = Dir(path & p & 
Fname)    Do While MyFile <> 0        Workbooks.Open (MyFile)        MyFile = 
Dir    LoopEnd Sub


Please help me in solving this issue. i know i am making some silly mistake but 
not able to understand why it is opening first file and giving error on second 
file. 

I would waiting for replies on this issue. 
-- 
Pankaj Pandey
Bhopal-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


 
  

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to