1

When I open the standard fileopen dialog using VBA (Word)

e.g., Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

I get what I ask for, but it's not what I want. I am defaulted to opening the selected file in the parent program. (If in Word, and displaying Excel files, the selected Excel file will open in Word, not the program associated with the .xls extension; if displaying PDF, the selected file will open in Word, etc.).

How can I get a Window's level (as opposed to application level) dialog to open so that when I click a document with a non-Word extension, the proper program associated with the file extension will be called. (I know that I can always right click on the file and click 'Open With . . . ', but I don't want to have to teach this to my staff if I can avoid it.)

Roy1953
  • 37
  • 5
  • Right click and choose Open. Default behaviour is to return the name selected to the application. It's a File - Open dialog. Also Office programs don't use Windows functions. They use shared functions that work Mac and Windows and areoffice specific. VBA programs can easily access Window features in a number of ways. But File Open dialogs from anywhere select on default action not Open. – Noodles Oct 05 '14 at 13:31
  • possible duplicate of [Using the browse for file dialog in Access VBA](http://stackoverflow.com/questions/4813598/using-the-browse-for-file-dialog-in-access-vba) – John Alexiou Oct 05 '14 at 15:48
  • See also http://www.codeproject.com/Articles/1459/A-Filebrowser-for-VBA – John Alexiou Oct 05 '14 at 15:49

1 Answers1

1
 Private Sub Tester()
    Dim fd As FileDialog, sh As Object
    Set fd = Application.FileDialog(msoFileDialogOpen)

    With fd
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "All files", "*.*"
        If .Show = -1 Then
            Set sh = CreateObject("Shell.Application")
            sh.Open .SelectedItems(1)
        End If
    End With

End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125