Solved

Dialogs(wdDialogFileOpen).Show -- Question!

Posted on 2004-04-29
8
1,091 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 24

Expert Comment

by:R_Rajesh
Comment Utility
what version are you using?

try changing  
fDialog As FileDialog
to
fDialog As object

R
0
 
LVL 9

Expert Comment

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

Expert Comment

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

Author Comment

by:dxve
Comment Utility

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
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 Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

763 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

13 Experts available now in Live!

Get 1:1 Help Now