0
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

错误/异常:

System.InvalidCastException 未处理消息=无法将“System.Boolean”类型的对象转换为“Microsoft.Office.Interop.Excel.Worksheet”类型。

这段代码有什么问题?

提前致谢。

4

1 回答 1

1

激活不返回工作表(它是一个子表)。

  oSheet4 = oWB4.Worksheets(2)
  oSheet4.Activate()
于 2012-07-04T19:47:03.157 回答