Okay another thing maybe you can help me with, I have always wondered if with VBA excel if you can search the entire directory to find a file and have that file and path be entered in cell ("A1"). Can this be done?
Okay another thing maybe you can help me with, I have always wondered if with VBA excel if you can search the entire directory to find a file and have that file and path be entered in cell ("A1"). Can this be done?
Not sure if this will help you or if it what you want. You can search for one file or multiples.
Sub GetImportFileName() ' Set up list of file filters Filt = "Text Files (*.txt),*.txt," & _ "Lotus Files (*.prn),*.prn," & _ "Comma Separated Files (*.csv),*.csv," & _ "ASCII Files (*.asc),*.asc," & _ "All Files (*.*),*.*" ' Display *.* by default FilterIndex = 5 ' Set the dialog box caption Title = "Select a File to Import" ' Get the file name Filename = Application.GetOpenFilename _ (FileFilter:=Filt, _ FilterIndex:=FilterIndex, _ Title:=Title) ' Exit if dialog box canceled If Filename = False Then MsgBox "No file was selected." Exit Sub End If ' Display full path and name of the file MsgBox "You selected " & Filename End Sub Sub GetImportFileName2() ' Set up list of file filters Filt = "Text Files (*.txt),*.txt," & _ "Lotus Files (*.prn),*.prn," & _ "Comma Separated Files (*.csv),*.csv," & _ "ASCII Files (*.asc),*.asc," & _ "All Files (*.*),*.*" ' Display *.* by default FilterIndex = 5 ' Set the dialog box caption Title = "Select a File to Import" ' Get the file name Filename = Application.GetOpenFilename _ (FileFilter:=Filt, _ FilterIndex:=FilterIndex, _ Title:=Title, _ MultiSelect:=True) ' Exit if dialog box canceled If Not IsArray(Filename) Then MsgBox "No file was selected." Exit Sub End If ' Display full path and name of the files For i = LBound(Filename) To UBound(Filename) Msg = Msg & Filename(i) & vbCrLf Next i MsgBox "You selected:" & vbCrLf & Msg End Sub
Oops. Forgot the code for putting it in cell A1. One sec.
Modify this code for both the single and multiple file selections:
Filename = Application.GetOpenFilename _ (FileFilter:=Filt, _ FilterIndex:=FilterIndex, _ Title:=Title, _ MultiSelect:=True) Sheet1.Range("A1") = Filename
Thank you, austenr
I can figure how to put in cell "a1" this this is very helpful for another project I am working and I save all of this stuff as well. What I really need is to do a search like (Search Results) the same as if you went to your desktop went to Start/Search/Find All Files And Folders In Explorer Windows. Have the program search in the same fashion then place the file i am looking for maybe placed in a input box and have that file and path put in Cell "a1".
O.K. Glad to help.
You might also want to check out this link
http://www.vba-programmer.com/VB_Cod...ingRuntime.txt
Your really helpful. Thanks again!
HTH. Take care
Hi gsouza, and welcome to VBA Express!
I'm not sure if you're aware of this, but if someone has answered your question to your satisfaction, you can mark your own threads solved! Just take a look in the 'Thread Tools" menu at the top of your post... it's a pretty great tool!
I'll get this one.
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!