Reputation: 37
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.)
Upvotes: 1
Views: 1285
Reputation: 166835
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
Upvotes: 1