Why would VBA TypeOf operator fail

后端 未结 3 1654
走了就别回头了
走了就别回头了 2021-01-08 00:34

I have been fighting with an Excel 2007 problem for several days now. Below is a listing of all facts I can think of that might be relevant:

  1. IDetailShee

3条回答
  •  孤街浪徒
    2021-01-08 01:08

    If you're not trusting TypeOf, plough on and ignore errors:

    Dim sht as EXCEL.WorkSheet
    For Each sht in ActiveWorkbook.Worksheets
      'If TypeOf sht is IDetailSheet Then
      Dim DetailSheet As IDetailSheet
      On Error Resume Next
      Set DetailSheet = sht
      On Error GoTo 0
      If Not DetailSheet Is Nothing Then
        DetailSheets.Add DetailSheet, DetailSheet.Name
      End If
    Next sht
    

    If this doesn't work, the worksheets really aren't IDetailSheet at that time at least.

提交回复
热议问题