Search code examples
vb.netopenfiledialog

How to open specific folder by Opendialog in VB?


I' m making program which export data from excel saved on disk to my textboxes in Form Application.

I have in code constant localization of excel.

 Dim ExcelApp As Excel.Application = New Excel.Application
    Dim ReteilerWorkbook As Excel.Workbook = ExcelApp.Workbooks.Open("C:\Users\TR\2.xlsx")

    With OpenFileDialog1
        .InitialDirectory = "C:\"
        .ShowDialog()
    End With   

Now i want to add button with opendialog to choose the Excel from different localization.


Solution

  • You can choose the file you want manually by using the OpenFileDialog

    Dim OpenFileDialog1 As New OpenFileDialog With {
                .CheckFileExists = True
            }
    
            If OpenFileDialog1.ShowDialog = DialogResult.OK Then
                Dim ExcelApp As Excel.Application = New Excel.Application
                Dim ReteilerWorkbook As Excel.Workbook = ExcelApp.Workbooks.Open(OpenFileDialog1.FileName)
    
            End If