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.Xlsx 04 L2.Xlsx 05 L1.Xlsx 05 L2.Xlsx 06 L1.Xlsx 06 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 String Dim Fname As String Dim 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 Loop End 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.