Why would VBA TypeOf operator fail

后端 未结 3 1670
走了就别回头了
走了就别回头了 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 00:57

    I found this question after posting my own similar issue as TypeOf fails to work with Excel workbook's ActiveSheet that implements interface

    I don't have a definitive explanation, but I think I do have a workaround.

    I suspect it is because [the code] is implementing an interface on Sheet1 or Chart, and is extending Sheet1/Chart1, but Sheet1 is already extending Worksheet (and Chart1 is already extending Chart).

    In my testing, I am able to force VBA to return the real value of TypeOf by firstly accessing a property of the sheet. That means, doing something ugly like:

    'Explicitly access ThisWorkbook.ActiveSheet.Name before using TypeOf
    If TypeOf ThisWorkbook.Sheets(ThisWorkbook.ActiveSheet.Name) Is PublicInterface Then
    

提交回复
热议问题