'Browse folder dialog' -where to find?

T

TANDEX

I am sorry. How to make macro to retrieve the folder name that the user
selected by calling the standard 'Browse folder dialog'? i.e. implement
integrated browsing capability, to select required folder via browsing, more
easily. Currently code use just input box where exact patch to folder should
be entered manually. I find no clear and good articles orcode snippets for
this simple task.

thanks
 
M

Martin Seelhofer

Hey TANDEX

If you're using Office XP or 2003, you can use the Folder Picker
standard dialog:

Dim folder As String
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "D:\temp\"
.Show
If .SelectedItems.Count > 0 Then
folder = .SelectedItems(1)
End If
End With

If folder = "" Then
MsgBox "Dialog cancelled..."
Else
MsgBox "The chosen folder was: " & folder
End If


Cheers,
Martin
 
T

TANDEX

Martin Seelhofer said:
Hey TANDEX

If you're using Office XP or 2003, you can use the Folder Picker
standard dialog:

Dim folder As String
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "D:\temp\"
.Show
If .SelectedItems.Count > 0 Then
folder = .SelectedItems(1)
End If
End With

If folder = "" Then
MsgBox "Dialog cancelled..."
Else
MsgBox "The chosen folder was: " & folder
End If


Cheers,
Martin
--------------------------------------------------------
Martin,

how to implement mentioned standard dialog in code below?

Sub FolderList()
'
' Example Macro to list the files contained in a folder.
'

Dim x As String, MyName As String
Dim i As Integer
Dim Response As Integer, TotalFiles As Integer

On Error Resume Next

Folder:

' Prompt the user for the folder to list.
x = InputBox(Prompt:="What folder do you want to list?" & vbCr & vbCr _
& "For example: C:\My Documents", _
Default:=Options.DefaultFilePath(wdDocumentsPath))

If x = "" Or x = " " Then
If MsgBox("Either you did not type a folder name correctly" _
& vbCr & "or you clicked Cancel. Do you want to quit?" _
& vbCr & vbCr & _
"If you want to type a folder name, click No." & vbCr & _
"If you want to quit, click Yes.", vbYesNo) = vbYes Then
Exit Sub
Else
GoTo Folder
End If
End If

' Test if folder exists.
If Dir(x, vbDirectory) = "" Then
MsgBox "The folder does not exist. Please try again."
GoTo Folder
End If

' Search the specified folder for files
' and type the listing in the document.
...
 

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