Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dialogs (Word 2000 sp3)

    Good evening one and all

    I need some information on using dialogs. I wish to have the user of a document navigate to a drive and folder where a certain file resides. (I plan to do this using a AutoOpen macro.) I then want to store the drive and path in an .ini file. I have tried the Dialogs(wdDialogFileFind) and the Display option however, I have no experience in using the dialogs and it does not seem to work properly. Does anyone have some code bits that I could use?

    I have read what I could find on this site about dialogs, however, the correct code alludes me.

    I know how to store the information once I have obtained it.

    Thanks

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: dialogs (Word 2000 sp3)

    Hi Rob

    I've only used the Win32 API for this purpose. The Code Project - A Filebrowser for VBA - VB / VBScript gives a good example (for Excel, but easily adaptable to Word) with the relevant supporting code for download. For Word, you can also store the user-defined path/ file details in a document variable, if you want to avoid an INI file for that express purpose.

    Alan

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: dialogs (Word 2000 sp3)

    If you want to let the user select a file, you can use

    Dim strFile As String
    With Application.Dialogs(wdDialogFileOpen)
    If .Display = True Then
    strFile = .Name
    End If
    End With

    If you want to let the user select a folder, you can use the BrowseFolder function (originally posted by Don Ceraso):

    Public Function BrowseFolder(Optional Title As String = "Select a Folder", Optional RootFolder As Variant) As String
    On Error Resume Next
    BrowseFolder = CreateObject("Shell.Application").BrowseForFolder( 0, Title, 0, RootFolder).Items.Item.Path
    End Function

    Use like this:

    Dim strFolder As String
    strFolder = BrowseFolder
    If Not strFolder = "" Then
    ' your code goes here
    End If

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: dialogs (Word 2000 sp3)

    Hans,

    These are very neat... much tighter and more compact than the API calls I'm entrenched with. I'll convert immediately, now I've seen the light!

    Alan

  5. #5
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: dialogs (Word 2000 sp3)

    Thanks Alan and Hans for your replies

    With your help and continued reading I think I have figured out the code that works for me. What I needed to do is get the full path where a certain file resides eg. D:Folder3Subfolder1. The actual file name does not have to be stored. The key to it is the 'WordBasic' argument.

    This is the code I ended up with:

    Dim strPath As String
    With Application.Dialogs(wdDialogFileOpen)
    If .Display = True Then
    strPath = WordBasic.FileNameInfo(.Name, 5)
    End If
    End With
    MsgBox strPath

    Again, thanks for your replies

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •