File open dialog

  • Thread starter Thread starter Jan Kronsell
  • Start date Start date
J

Jan Kronsell

Hi NG

I would like to display the file open dialog in a certain folder and with
only a specific filetype (CSV) show.

This will do the first part

ChDir "c:\Burn"
Application.Dialogs(xlDialogOpen).Show

but how do I select a specific filetype only.

Jan
 
I forgot: I would also like to check for any files in the folder before
displaying the file open dialog. If no files are found it should not show
the dialog, but a msgbox.

jan
 
Hi

Try this...

****************************************************
Sub FileOpen()

Dim vntFileToOpen As Variant
Dim strFileExist As string

strFileExist = Dir("C:\Folder\*.CSV")

If Not strFileExist = "" Then
'Get Open File Dialog
vntFileToOpen = Application.GetOpenFilename("CSV (*.csv), .csv")

'returns boolean False if Cancel is clicked:
If vntFileToOpen = False Then
'User cancelled so just exit
Exit Sub
End If

Else
'Display message
MsgBox "No File with the extension .csv exists", vbOK, "No File"

End If

End Sub
****************************************************
This is untested code so if its doesn't work get back to me.

Tom
 
This would work if the default directory is C:\Folder. If not, you would
need to add to this code:

Sub FileOpen()

Dim vntFileToOpen As Variant
Dim strFileExist As string
Dim strPath = "C:\Folder"
Chdrive strPath
ChDir strPath

strFileExist = Dir(strPath & "\*.CSV")

If Not strFileExist = "" Then
'Get Open File Dialog
vntFileToOpen = Application.GetOpenFilename("CSV (*.csv), .csv")

'returns boolean False if Cancel is clicked:
If vntFileToOpen = False Then
'User cancelled so just exit
Exit Sub
End If
 
Back
Top