DIR to open seached file

SuperBaby

New Member
Joined
Apr 17, 2013
Messages
24
Hi,

Sorry if this is something you will say there are plenty of them everywhere. I know that. I have been through the whole day but I cannot fix one last thing.

I have the code below which I copied from around the forums (sorry I dont remember all). I would like to know if you would please kindly fix it for me like when I enter the specific file name in my cell A1 and it can search for only that specific file name and open. What I have been look trhough the whole day are only to open every file.

Code:
[COLOR=#0000ff]Sub[/COLOR] A() 
    [COLOR=blue]Dim[/COLOR] wb [COLOR=blue]As[/COLOR] Workbook 
    [COLOR=blue]Dim[/COLOR] sLook() [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR], vLook [COLOR=blue]As[/COLOR] [COLOR=blue]Variant[/COLOR] 
    [COLOR=blue]Dim[/COLOR] fName [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR] 
     
    ReDim sLook(1 [COLOR=blue]To[/COLOR] 2) [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR] 
    sLook(1) = "C:\Ongoing\" 
    sLook(2) = "C:\Finishing\" 
     
    [COLOR=blue]For Each[/COLOR] vLook [COLOR=blue]In[/COLOR] sLook 
         
        fName = Dir(vLook & "*.xlsx") 
        Set wb = Workbooks.Open(Filename:=vlook & fname, ReadOnly:=True)
        wb.Close Savechanges:=False            
        fName = Dir 
    [COLOR=blue]Next[/COLOR] vLook 
     
[COLOR=blue]End Sub[/COLOR]
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
If you want the user to open only the file whose name is already written in A1, then why would you need to ask him to look for it?
 
Upvote 0
Hi Jacqueslegrand,

Thanks for your reply. Because there are more than thousand file in the folder I meant to. I want my user to type in the file name like 2007021 in A1 and push the button or some thing to find this file in the folder and open it. In addition, probably they dont know which path this file is in so this can ease them.
Please help. Thank you so much.
 
Upvote 0
I got this and it works great. I modify them small

Code:
Sub A()
Dim wb12 As Workbook
Dim strFile As String
strFile = Dir("C:\Ongoing\" & ThisWorkbook.ActiveSheet.Range("A1") & ".xlsx", vbNormal)
'now check if anything was found:
If strFile = "" Then
MsgBox "File Not Found!"
End
Else
MsgBox strFile
Set wb12 = Workbooks.Open(FileName:= _
            "C:\Ongoing\" & ThisWorkbook.ActiveSheet.Range("A1") & ".xlsx")
End If
End Sub

Thanks to this post
http://www.mrexcel.com/forum/excel-questions/690821-macro-find-specific-file-folder.html
 
Upvote 0

Forum statistics

Threads
1,203,070
Messages
6,053,368
Members
444,658
Latest member
lhollingsworth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top