Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Return File Name only (not open the file) (2000/97)

    I am trying to create a macro that will display the File Open dialog box and let me select 1 or more files. However, I do not want to open the files, I only want to return the file names to be used for some other procedure.

    I know that Excel has the GetOpenFilename function, but this does not work in Word.

    Does word have a feature similar to this? If not, does any one have a solution that will perform the same function?

    Thanks.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Return File Name only (not open the file) (2000/97)

    This usually is done by calling the File Open dialog with the .Display method rather than the .Show method. When the user closes the dialog, you can access the .Name property. It's all very poorly documented, but try this:

    Sub GetFileNames()
    Dim strFileName As String
    With Dialogs(wdDialogFileOpen)
    .Display
    strFileName = .Name
    End With
    MsgBox strFileName
    End Sub

    This does not work if you select multiple files (an error pops up). I think there have been some threads on this problem on this board or the VBA board during the past 6 months.

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Return File Name only (not open the file) (2000/97)

    I have already tried a routine similar to this one. The problem is that I need to select multiple files.

    Thanks.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Return File Name only (not open the file) (2000/97)

    My suggested forum search turned up this thead, in which the rough consensus appeared to be that you could not do it with the CommandBar trick either (it open the files rather than returning names): <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=wrd&Number=106318&page=&vie w=&sb=&o=&vc=1>wdDialogFile Open (Office 2000)</A>. If there were an event called DocumentBeforeOpen, you could do it, but no, there is no such event.

    Plan B probably is to use a Windows browsing dialog rather than the built-in Word dialog. Hopefully someone has implemented this, since it's a bit late in the day for me to start from scratch!

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Return File Name only (not open the file) (2000/97)

    I have a way to use the Windows File Dialog box. However, like the Word Dialog box, it can only handle one file name. I need to select two files from the interface. If you would like, I could attach a file with the routine that I am using.

    I usually develop in Excel and this is a piece of cake with the GetOpenFile function. I just wonder why Word does not have a similar function.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Return File Name only (not open the file) (2000/97)

    Can you call an instance of the Excel Application and display the FileOpen dialog from there and hence use the GetFileOpen function running in the instance of Excel?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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