theXact
06-08-2010, 10:43 AM
Hello,
I need to create a button that when clicked will open up a windows file browser. From here I am able to select multiple files and when I click "open" all of those files will be read into the program.
If anyone knows how you would do this of if its possible that would be great!
Thanks!
TheRealTinTin
06-08-2010, 12:20 PM
In relation to the "windows file browser" and selecting multiple files, you should look around for the Excel dialogs function. In it's simplest form, it looks likeApplication.Dialogs(xlDialogOpen).ShowHowever, arguments can be changed to filter for specific file types/locations etc. and also to return multiple files.
As far as "read into the program" goes, you'll need to be a bit more specific. Are you wanting to open the files for the user to be able to see them? Or is there some other action you want to perform?
theXact
06-08-2010, 02:19 PM
Hi,
Thanks for the reply. A dialog function sounds like it would do the trick. The program needs to read the information from the file and process it into other excel functions. Really I just need the file paths and I know how to do the rest from there.
If anyone knows of any good examples on how to use a dialog box for getting multiple file paths that would be very helpfull!
Thanks!
zebulon72
06-09-2010, 02:17 AM
Are your file pahts known or unknown?
Or do you have several unknown filenames in the same dir?
What is the criteria for files to open (manually), how do the user choose what files to open?
theXact
06-09-2010, 10:23 AM
Basically, there will be a bunch of .txt files which contain information for an object. The objects name is the name of the .txt file. For example, if it were with cars, the name of the car would be the name of the .txt file and the text inside would be information about the car.
What I want is for the user to be able to open a file browser (similar to a windows file browser), and select all the .txt files they want to uset, via shift/ctrl click. And then after hitting OK those file paths will be sent to the program for it to open and use.
Hopefully this clears it up, if there is anything else let me know.
TheRealTinTin
06-09-2010, 10:53 AM
Another method you could use is the GetOpenFilename, which might be easier for what you want to do. I've provided a simple example below of how this could workPrivate Sub GetFilename()
' Dimension variables
Dim FileNm As Variant
Dim FileLp As Integer
' Display "Open File" dialog for user to select files
FileNm = Application.GetOpenFilename(FileFilter:="Text Files,*.txt", _
MultiSelect:=True)
' Check if user pressed cancel
If TypeName(VarName:=FileNm) = "Boolean" Then Exit Sub
' Handle files
For FileLp = LBound(FileNm) To UBound(FileNm)
' (Here, is where you would put thhe bulk of your code that does whatever processing you want to do for each file)
Debug.Print FileNm(FileLp)
Next
End Sub
theXact
06-09-2010, 11:29 AM
Another method you could use is the GetOpenFilename, which might be easier for what you want to do. I've provided a simple example below of how this could workPrivate Sub GetFilename()
' Dimension variables
Dim FileNm As Variant
Dim FileLp As Integer
' Display "Open File" dialog for user to select files
FileNm = Application.GetOpenFilename(FileFilter:="Text Files,*.txt", _
MultiSelect:=True)
' Check if user pressed cancel
If TypeName(VarName:=FileNm) = "Boolean" Then Exit Sub
' Handle files
For FileLp = LBound(FileNm) To UBound(FileNm)
' (Here, is where you would put thhe bulk of your code that does whatever processing you want to do for each file)
Debug.Print FileNm(FileLp)
Next
End Sub
This is perfect! Thank you very much!