Directory selection with Dialogs(wdDialog...

A

Aldo

Hi all,

I need to select a directory with a dialogbox.

I'm trying to do it the Dialogs(wdOpenFileName) but I can just select a
file, not only a directory

Anybody could help me ?

I'm also looking for good web sites with samples and tutorials on VBA (to
avoid newbie question as this one)

Thanks
 
T

Tony Jollans

What happens when you do this?

With Application.Dialogs(wdDialogFileOpen)
.Name = "C:\Your path\followed by delimiter\"
.Show
End With

Enjoy,
Tony
 
A

Aldo

Hi Tony,

it's exactly what I do but I cannot select only a directory and validate, I
have to select a file but It's not what I want to do.
I just want a dialogbox to allow me to get a path to a location

Thanks,
Aldo
 
T

Tony Jollans

Hi Aldo,

Are you putting the path delimiter (the backslash) at the end? It makes a
difference.

Enjoy,
Tony
 
J

Jonathan West

Hi Aldo,

If you are using Office XP or later, you can use the FileDialog object, like
this

Function BrowseFolder() As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show Then
BrowseFolder = .SelectedItems(1) & "\"
End If
End With
End Function


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


If you are on Word 2000 or Word 97, you e
 
A

Aldo

Hi Tony

Here my code. When the dialoxbox appears, if I don't select a file, I have
only teh Cancel button activated

Private Sub BUTTON_Modifiey_Input_Directory_Click()
With Dialogs(wdDialogFileOpen)
.Name = Label_Input_Directory + "\"
.Show
End With

End Sub

Thanks
 
T

Tony Jollans

You only have the cancel button activated because that is all you can do
until you select a file (or folder) within the displayed folder. I'm not
sure I understand what you want.

Enjoy,
Tony
 
A

Aldo

Hi Tony

I just want to be able to select a folder - click Ok - then the dialog
disappears and I can get the path of the selected folder in a vba variable.
With my code, when I select a folder in the dialog box and click OK, it
opens it but the dialog stays active until I have selected a file

Thanks
Aldo
 
A

Aldo

Many thanks it works fine
2 questions :
- Is it possible to predefine the folder that appears in the dialog
- Any chance to have a solution for Windows 2000 (then macro i'm working on
must work on XP and 2000)
Thanks again
 
T

Tony Jollans

I was about to suggest this when I saw it had already been suggested. You
can set the initial file with ..

With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "C:\etc"
.Show etc.

Enjoy,
Tony
 
J

Jonathan West

Aldo said:
Many thanks it works fine
2 questions :
- Is it possible to predefine the folder that appears in the dialog
- Any chance to have a solution for Windows 2000 (then macro i'm working
on must work on XP and 2000)
Thanks again

Windows 2000 or Office 2000? If you have Office XP or later, the solution I
have will work on any version of Windows.

If you are using Office 2000, then you can use this solution

Function BrowseFolder(Optional InitDir As String = "") As String
Dim strFolder As String
With Dialogs(wdDialogCopyFile)
If Len(InitDir) > 0 Then
.Directory = InitDir
End If
If .Display <> 0 Then
strFolder = .Directory
If Asc(strFolder) = 34 Then
strFolder = Mid$(strFolder, 2, Len(strFolder) - 2)
End If
BrowseFolder = strFolder
End If
End With
End Function

If you pass the InitDir parameter, the dialog will open at at folder.
otherwise it will open at the last used folder.
 
A

Aldo

Many thanks - Works fine on Office 2000 under windows 2000

One more small detail : is it possible to change the dialog caption

Thanks
 

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