Freedom Computers

ACCESS

DIR or Find a file

' Requires reference to Microsoft Office 14.0 Object Library.


' OPEN A FILE


Dim fDialog As Office.FileDialog


Dim varFile As Variant


' Set up the File Dialog.


Set fDialog = Application.FileDialog(msoFileDialogFilePicker)


With fDialog


' Allow user to make multiple selections in dialog box


.AllowMultiSelect = False



' Set the title of the dialog box.


.Title = "Please select a file"


' Clear out the current filters, and add our own.


.Filters.Clear


.Filters.Add "CSV Files", "*.csv"


' .Filters.Add "All Files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked a file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then

'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
CSVFile = varFile ' Me.FileList.AddItem varFile
Next

Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With


DIR Simple Version
Posted by Brixham Mike at 12:35, November 11 2013.

Dim f As Object
Set f = Application.FileDialog(3)
With f
.Title = "Please select a file"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "CSV Files", "*.*"
If .Show = True Then
For Each varFile In .SelectedItems
csvfile = varFile ' Me.FileList.AddItem varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
MsgBox "file choosen = " & csvfile