Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dialogs(wdDialogFileOpen).Show -- Question!

Posted on 2004-04-29
8
Medium Priority
?
1,150 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 2000 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
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
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…

730 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