FancyPrairie
Programmer
I got the following code off the net. It pops up a browse dialog window from which I should be able to choose a file or folder. I can choose the file I want, but the code fails to tell me which file I've chosen.
I pulled other examples off the net with the same results. That is, the code I've found always returns the folder selected. But I can't find an example that returns/displays the file I've chosen.
Any ideas?
I pulled other examples off the net with the same results. That is, the code I've found always returns the folder selected. But I can't find an example that returns/displays the file I've chosen.
Any ideas?
Code:
Option Explicit
MsgBox BrowseForFolder("File","Browse a File")
MsgBox BrowseForFolder("Folder","Browse a Folder")
Function BrowseForFolder(sBFF,sPMT)
BrowseForFolder = ""
If sBFF <> "Folder" And sBFF <> "File" Then Exit Function
'*
Dim objSHL
Set objSHL = CreateObject("Shell.Application")
Dim objB4F
'*
On Error Resume Next
If sBFF = "Folder" Then
Set objB4F = objSHL.BrowseForFolder(&H0,sPMT,&H0031,&H0011)
Else
objB4F = objSHL.BrowseForFolder(&H0,sPMT,&H4031,&H0011)
End If
BrowseForFolder = objB4F.ParentFolder.ParseName(objB4F.Title).Path
If Err.Number <> 0 Then BrowseForFolder = ""
'*
Set objB4F = Nothing
Set objSHL = Nothing
End Function