Hi there,
This is the code for opening various files using vb applicaton but here i need to provide the path for file. i want to open any file using vb app using Open Dialog control.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()
ShellExecute 0&, "OPEN", "D:\test\MCA.pdf", "", "", 1
End Sub

Private Sub Command2_Click()
ShellExecute 0&, "OPEN", "D:\test\MCA.docx", "", "", 1
End Sub

Private Sub Command3_Click()
ShellExecute 0&, "OPEN", "D:\test\MCA.txt", "", "", 1
End Sub

Private Sub Command4_Click()
ShellExecute 0&, "OPEN", "D:\test\MCA.xlsx", "", "", 1
End Sub

Private Sub Command5_Click()
ShellExecute 0&, "OPEN", "D:\test\MCA.jpg", "", "", 1
End Sub

What i did is just i created a folder named "test" in my D drive and put some files(MCA.xlsx,MCA.jpg,MCA.txt,MCA.docx and MCA.pdf). Now i want to open any file by browsing my local drive on click of buttons.

Private Sub ToggleButton1_Click()

Dim fd As FileDialog
Dim objfl As Variant
Dim filnam As String

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
    .ButtonName = "Select"
    .AllowMultiSelect = False
    .Filters.Add "Text Files", "*.txt;*.csv;*.tab;*.asc"
    .Title = "Choose Transactions file to import"
    .InitialView = msoFileDialogViewDetails
    .Show
    For Each objfl In .SelectedItems
        filnam = objfl
    Next objfl
    On Error GoTo 0
End With

Set fd = Nothing
End Sub

I hope this might help you...............
I did not test it....

This article has been dead for over six months. Start a new discussion instead.