Wednesday, March 2, 2016

Excel VBA- File Dialog

EXCEL VBA HOW TO ENABLE THE USER TO BROWSE AND OPEN AN EXCEL WORKBOOK

File Path
C:\Users\Documents\NOV Report.xlsm
Click To Browse

To achieve this objective, following steps can be used:
1.       Design a user interface on the excel sheet as shown above.
2.       The user clicks at the browse button.
3.       The user chooses her/his desired excel workbook.
4.       The complete path of the workbook is displayed in the User Interface Cell.
5.       The cell displaying the file path is named as rngFilePathCell manually using Name manager or Name Box.

Text Box: Browse Invoice
Sub Rectangle1_Click()

    Dim strFilePath  As String

    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "EXCEL FILES ", "*.xls?"
        .Title = "Choose the excel file"

        If .Show = -1 Then
            If .SelectedItems.Count = 1 Then
            strFilePath = .SelectedItems(1)
            Range("rngFilePathCell") = strFilePath
            End If
        End If
    End With
 
   Workbooks.Open Range("rngFilePathCell")

End Sub

No comments:

Post a Comment

Hot Topics