You can use this to identify the sheet names (hidden sheets as well).
Instead of logging the sheet names, you can pass an out argument of sheet names and store it in excel table.
Thanks Robin for the clear replies along with the samples.
When I apply the the codes that you amended slightly, there is still an error which I am unsure of how to resolve it:
Error ERROR Validation Error No compiled code to run error BC30456: âXISheetVisibilityâ is not a member of âMicrosoft.Office.Interop.Excelâ. At line 8
I have also inputted a value for the argument, which is linking to a variable that I have created with the file path details.
Would you mind advising what went wrong or what I have to correct from the above?
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb1 As Microsoft.Office.Interop.Excel.Workbook
Dim ws1 As Microsoft.Office.Interop.Excel.Worksheet
excel = New Microsoft.Office.Interop.Excel.ApplicationClass
wb1 = excel.Workbooks.Open(âYour excel pathâ)
For Each sheet As Microsoft.Office.Interop.Excel.Worksheet In wb1.Sheets
If(sheet.Visible=Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetHidden)
Console.WriteLine(sheet.Name)
End If
Next
wb1.Save
wb1.Close
excel.Quit
ws1 = Nothing
wb1 = Nothing
excel = Nothing
GC.Collect
i think you have to import Microsoft.office.interop.excel package in your manage packages section. please try and let us know. thanks
or type cast like below.
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb1 As Microsoft.Office.Interop.Excel.Workbook
Dim ws1 As Microsoft.Office.Interop.Excel.Worksheet
excel = New Microsoft.Office.Interop.Excel.ApplicationClass
wb1 = excel.Workbooks.Open(âC://kiranâ)
For Each sheet As Microsoft.Office.Interop.Excel.Worksheet In wb1.Sheets
If(CType((sheet.Visible),Boolean) =False)
Console.WriteLine(sheet.Name)
End If
Next
wb1.Save
wb1.Close
excel.Quit
ws1 = Nothing
wb1 = Nothing
excel = Nothing
GC.Collect