Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Windows Dialog for getting a path

Status
Not open for further replies.

ckpeel

Technical User
Jan 4, 2002
20
CA
I want to create a class that will allow a user to navigate via a windows dialog to a directory simply hit enter and return that path to my main code.

I have this with the comdlg32 and GetOpenFileNameA (lots of samples are around for this). I dug through MSDN around an API called GETPATH .. but it wasn't help full to me. I have no MFC background only VB and VBA. If anyone can help me get this working it would be greatly appreciated.

I'm doing this in Word VBA btw.

Chris.
chrisp@aci.on.ca
 
You may be able to use something like this:
Code:
Sub test()
Code:
'Offer user dialog box for file open (to set path)
Code:
  With Dialogs(wdDialogFileOpen)
    .Name = "*.doc"
    Button = .Display
Code:
    ' We really don't care what name, but just in case...
Code:
    SelectedFile = .Name
  End With
  If Button = -1 Then
    MsgBox "Current Path: " _
      + Options.DefaultFilePath(wdCurrentFolderPath)
  Else
    MsgBox "Clicked Cancel"
  End If
End Sub

 
Thanks. This still requires the user to actually click on a file. then the code you provided displays the folder information.

What i want is the ability to actually just click the folder and then ok. It's a little differnet - I need the user to specify a default directory and I don't want them to deal with typing it out.

chris
 
Some one sent me the answe I was looking for....
Use the Copy File dialog:

With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
MsgBox &quot;You chose &quot; & .Directory
Else
MsgBox &quot;Dialog cancelled&quot;
End If
End With

The advantage is that it is quick & simple, but the disadvantage is that you can't change the caption of the dialog, which says “Copy”.


Better solution can be found at:


Thanks Zathras for your help and prompt reply.
 
Chris,

The links you put up seem to use VB or word. Is there way to do this in just VBA in Excel?

-Venkman
 
A somewhat silly solution might be:

set wd=createobject(&quot;word.application&quot;)
wd.visible=true
with wd.dialogs(300)
.show
If .Display <> 0 Then
MsgBox &quot;You chose &quot; & .Directory
Else
MsgBox &quot;Dialog cancelled&quot;
End If
end with
wd.quit

Rob
[flowerface]
 
Excel has something called:

Application.Dialogs(xlDialogOpen).Show

but I can't seem to make it work like it does in Word?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top