Solved

Dialogs(wdDialogFileOpen).Show -- Question!

Posted on 2004-04-29
8
1,100 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now