Picking an empty folder

N

Neil Humphries

How do I allow a user to browse to and select an empty folder?
I am using Word XP and later.

If I use a file picker dialog box, the user must select a file. I can
extract the path, but the user can't select a folder that has no files in it.

If I use a folder picker dialog box, the user can't browse freely; only to
folders below the initial one.
 
G

Graham Mayor

The user should be able to browse anywhere with the folderpicker dialog box

Dim strFile As String
Dim strPath As String
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
Again:
With fDialog
.Title = "Select Folder containing the documents and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
strFile = Dir$(strPath & "*.do?")
If Len(strFile) > 0 Then
MsgBox "This folder contains files?", vbExclamation, "Contains Files"
GoTo Again
End If
MsgBox strPath & " is an empty folder"


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top