Link to home
Start Free TrialLog in
Avatar of dxve
dxve

asked on

Dialogs(wdDialogFileOpen).Show -- Question!

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 :)
ASKER CERTIFIED SOLUTION
Avatar of gilbar
gilbar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gilbar
gilbar

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)
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
Avatar of dxve

ASKER


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 :)
what version are you using?

try changing  
fDialog As FileDialog
to
fDialog As object

R
glas to help dx, and thanx for points!
well, i am afraid  FileDialog object is supported in officexp or above
:)
Rajesh
Avatar of dxve

ASKER


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!