> Hmm, I wonder if you could use the FileOpen dialog and just filter
> for the path...
This allows using a dummy filename...
Sub PickFolder()
Dim sf$, sp$, lRet&
sf = "MyFile"
'SaveAs
lRet = CD_ShowOpen_Save(Application.hWnd, , sf, sp, , , , , False)
Debug.Print Mid(sf, 1, Len(sf) - Len(sp))
End Sub
..and returns the path like so...
C:\Users\Garry\
..even if the user selects a filename or changes the dummy filename.
This requires user to select an existing fiename, and so won't work
with empty folders...
Sub PickFolder()
Dim sf$, sp$, lRet&
sf = "MyFile"
'Open
lRet = CD_ShowOpen_Save(Application.hWnd, , sf, sp)
Debug.Print Mid(sf, 1, Len(sf) - Len(sp))
End Sub
Normally, I use the following and specify 'Drives' as the top level
folder so users must drill down...
Function GetDirectory$(Optional OpenAt, Optional MSG$)
' Returns the path of a user selected folder
' Note: By default, dialog opens at 'Desktop'
' Args:
' OpenAt Optional: Path to the dialog's top level folder
' Msg Optional: The dialog's title
If MSG = "" Then MSG = "Please choose a folder"
On Error Resume Next '//if user cancels
GetDirectory = CreateObject("Shell.Application").BrowseForFolder(0,
MSG, &H40 Or &H10, OpenAt).Self.Path
End Function 'GetDirectory()
..and use it like this...
sPath = GetDirectory(SpclFldrs.osDrvs)
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
..where SpclFldrs is an enum of all the special folder constants and
osDrvs=17. (Note that the trailing backslash will be missing and so
requires appending)
Otherwise I just pass the top level path under which I want users to
search!