Private Sub Button11_Click()
Dim oXL4 As New Excel.Application
Dim oWB4 As Excel.Workbook
Dim oSheet4 As Excel.Worksheet
If ComboBox10.Text = "abc" Then
oWB4 = oXL4.Workbooks.Open("D:\blah\blah\Def.xlsx")
oSheet4 = oWB4.Worksheets(2).Activate
oXL4.Visible = True
oXL4.UserControl = True
End If
End Sub
Error/Exception:
System.InvalidCastException was unhandled
Message=Unable to cast object of type ‘System.Boolean’ to type ‘Microsoft.Office.Interop.Excel.Worksheet’.
What is wrong with this code?
Thanks in advance.
Activate does not return a worksheet (it’s a sub).