I try to get sheets name from file excel using vb.net and show them into textbox. I was try with this code:
Imports Microsoft.Office.Interop
Private Sub GetSheetsName
Dim efa As New Excel.Application
Dim ewb As Excel.Workbook
Dim ews As Excel.Worksheet
Dim fileName as string
fileName="D:\test.xls"
ewb = efa.Workbooks.Open(fileName)
For Each ews In ewb.Worksheets
ExcelSheetName += ews.Name & vbNewLine
Next ews
TextBox1.text=ExcelSheetName
end sub
That code was work for file excel *.xls, in textbox show Sheets Name from file test.xls
Sheet1
Sheet2
Sheet3
But when I try with excel 2007 (*.xlsx), then show an error message like this.

What should I do? Can you help me please.
Try this code: