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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Return File Name only (not open the file) (2000/97)

    Author
    Topic
    #366622

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #569239

      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.

      • #569267

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

        Thanks.

        • #569268

          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): wdDialogFile Open (Office 2000). 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!

          • #569668

            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.

            • #569821

              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?

    Viewing 0 reply threads
    Reply To: Return File Name only (not open the file) (2000/97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: