Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find files in directories

Status
Not open for further replies.

johant1957

Programmer
Nov 30, 2009
4
NL
Hi,

I have entered the code for showing me a directory list when I want to import an excel file. But I can only see Maps, no files. Can anybody help me so I can see and select the files I want to use?
CODE:
Sub Show_BrowseDirectory_dialog()

Dim dirInfo As BROWSEINFO
Dim path As String

Dim r As Long, X As Long, pos As Integer

dirInfo.pidlRoot = 0&
dirInfo.lpszTitle = "Selecteer een map"
dirInfo.ulFlags = &H1

X = SHBrowseForFolder(dirInfo)
path = Space$(512)
r = SHGetPathFromIDList(ByVal X, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
MsgBox ("U heeft geselecteerd := " & Left(path, pos - 1))
Else
MsgBox ("Selecteer een folder")
End If

End Sub


Kind regards
 
The code you have there is to browse only folders, it doesn't display files.

You might want to have a look at the Application.FileDialog for this task.

Hope this helps



Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Hi,

Thanks, but I did try this, saw it in the help-files, used it in my code, but get errors. Then I get a message like "Type Mismatch".

Johan
 
Hi Johan,

Could you show us the code you tried to use with it?

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Here's an example from the ms help file with a basic filter for excel files added (contains original ms comments):
Code:
Dim dlgOpen As FileDialog
Dim vrtSelectedItem As Variant

Set dlgOpen = Application.FileDialog(msoFileDialogOpen)

With dlgOpen
    .Filters.Add "Microsoft Excel Files", "*.xl*; *.xls", 1

    .AllowMultiSelect = True

    If .Show = -1 Then
                'Step through each string in the FileDialogSelectedItems collection.
                For Each vrtSelectedItem In .SelectedItems

                    'vrtSelectedItem is a String that contains the path of each selected item.
                    'You can use any file I/O functions that you want to work with this path.
                    'This example simply displays the path in a message box.
                    MsgBox "Selected item's path: " & vrtSelectedItem

                Next vrtSelectedItem
    End If

End With
Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Hi,

Here is the code:
Dim dlgOpen As Dialog
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
dlgOpen.Show
Kind regards,

Johan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top