Invoke Code (VB.Net) Activity to hide some Excel sheets

Dear All

Even though I am a newbie of VBnet, I tried to open an Excel (Argument Name: in_File) and hide all sheets whose names do not contain “PIVOT” or “ERROR”. Invoke Code Activity displays “Option Strict On disallows late binding at line 7”. It would be greatly helpful if you could advise me what’s wrong with the codes below… Thanks in advance!

Dim excel As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook = excel.Workbooks.Open(in_File)
excel.Visible = False
For i As Integer = 1 To wb.Sheets.Count
	Dim sh As Microsoft.Office.Interop.Excel.Worksheet = CType(wb.Sheets(i), Microsoft.Office.Interop.Excel.Worksheet)
	If Instr(Ucase(sh.Name), "PIVOT") = 0 And Instr(Ucase(sh.Name), "ERROR") = 0 Then
		sh.Application.Visible = Excel.XlSheetVisibility.xlSheetHidden			
	End If

Change this to False

Try below code.
This is to hide single sheet but you can put your loop to hide all sheet.
HideSheet.xaml (5.4 KB)

Thank you both. I have just found out the issue in my codes.

sh.Application.Visible = Excel.XlSheetVisibility.xlSheetHidden	

should have been

sh.Visible = Excel.XlSheetVisibility.xlSheetHidden	

This can help codes worked as intended.