Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Directory selection with Dialogs(wdDialog...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aldo - 02 Oct 2005 13:27 GMT
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
Tony Jollans - 02 Oct 2005 13:45 GMT
What happens when  you do this?

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

Enjoy,
Tony

> Hi all,
>
[quoted text clipped - 9 lines]
>
> Thanks
Aldo - 02 Oct 2005 13:51 GMT
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

> What happens when  you do this?
>
[quoted text clipped - 19 lines]
>>
>> Thanks
Tony Jollans - 02 Oct 2005 14:06 GMT
Hi Aldo,

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

Enjoy,
Tony

> Hi Tony,
>
[quoted text clipped - 28 lines]
> >>
> >> Thanks
Aldo - 02 Oct 2005 15:44 GMT
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

> Hi Aldo,
>
[quoted text clipped - 39 lines]
>> >>
>> >> Thanks
Tony Jollans - 02 Oct 2005 16:03 GMT
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

> Hi Tony
>
[quoted text clipped - 54 lines]
> >> >>
> >> >> Thanks
Aldo - 02 Oct 2005 16:11 GMT
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

> 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
[quoted text clipped - 66 lines]
>> >> >>
>> >> >> Thanks
Jonathan West - 02 Oct 2005 15:35 GMT
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

Signature

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

> Hi all,
>
[quoted text clipped - 9 lines]
>
> Thanks
Aldo - 02 Oct 2005 16:17 GMT
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

> Hi Aldo,
>
[quoted text clipped - 23 lines]
>>
>> Thanks
Tony Jollans - 02 Oct 2005 16:41 GMT
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

> Many thanks it works fine
> 2 questions :
[quoted text clipped - 37 lines]
> >>
> >> Thanks
Jonathan West - 02 Oct 2005 17:46 GMT
> 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.

Signature

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

Aldo - 02 Oct 2005 18:29 GMT
Many thanks - Works fine on Office 2000 under windows 2000

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

Thanks

>> Many thanks it works fine
>> 2 questions :
[quoted text clipped - 26 lines]
> If you pass the InitDir parameter, the dialog will open at at folder.
> otherwise it will open at the last used folder.
Jonathan West - 03 Oct 2005 17:24 GMT
> Many thanks - Works fine on Office 2000 under windows 2000
>
> One more small detail : is it possible to change the dialog caption

Unfortunately not. for that, you would need to start looking outside Word
for solutions. Take a look here

How to allow the user to browse to and select a folder
http://www.word.mvps.org/FAQs/MacrosVBA/BrowsDialog.htm

Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.