Solved

Dialogs(wdDialogFileOpen).Show -- Question!

Posted on 2004-04-29
8
1,135 Views
Last Modified: 2012-06-22
I'm trying to write a macro to gather information (a directory path) from the user. These directory paths are going to be complex, hence I would like to display an explorer window to allow navigation if possible, rather than having the user type the path into an inputbox -- which would lead to typos inevitably.

Does anyone know if their is a way to get an explorer box to open and then record the selected folder path (without opening the selected file).  I've played around with Dialogs(wdDialogFileOpen).Show etc but this just opens the selected file, and i cant find a way to extract the folder path from it, either way!

Thanks in advance for any ideas :)
0
Comment
Question by:dxve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Accepted Solution

by:
gilbar earned 500 total points
ID: 10959863
this should to the trick:

Sub q()
    Dim dirF As String 'this will hold path selected in dialogbox
    Set Doc = Dialogs(wdDialogFileOpen)
    With Doc
       .Name = "*.txt"
       BClicked = .Display
    End With
    dirF = CurDir
End Sub

0
 
LVL 9

Expert Comment

by:gilbar
ID: 10959942
you probably want the line
   .Name =  
to be set to

  .Name = "*.*

won't make any difference for getting paths, but no need (in this case) to only show txt files.  The key line is the  CurDir  line, which shows the current directory (which was updated by the user in the dialog box)
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10959984
dxve,

vba provides a way to browse for folders.

Sub myFolder()
Dim sFolderName As String, fDialog As FileDialog, ret As Long
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
ret = fDialog.Show
If ret <> 0 Then
sFolderName = fDialog.SelectedItems(1) & Application.PathSeparator
MsgBox sFolderName
Else
MsgBox "User pressed cancel"
End If
Set fDialog = Nothing
End Sub

Rajesh
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:dxve
ID: 10960986

gilbar,

Worked like a champ! Thank you much! Points awarded :)


Rajesh,

Your solution looks interesting. I got a compile error "User defined type not defined" -- referring to the "fDialog As FileDialog" line however when I ran it. It's always great to see more than one techniques for solving a problem and yours is different enough from the accepted answer that it would be interesting to compare. If you want to follow up with a correction here to get your code working I'll post points for you separately :)
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10961049
what version are you using?

try changing  
fDialog As FileDialog
to
fDialog As object

R
0
 
LVL 9

Expert Comment

by:gilbar
ID: 10961107
glas to help dx, and thanx for points!
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10961168
well, i am afraid  FileDialog object is supported in officexp or above
:)
Rajesh
0
 
LVL 1

Author Comment

by:dxve
ID: 10961618

Rajesh

Ahh, there's the problem then. I have a mixture of machines running Win2k/Office2k through to WinXP/OfficeXP. The PC I was testing on was running office2k. Guess I should have specificed the Office 2k part as I need to run with the lowest spec machines for consistency. My bad!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question