检查一个Excel对象是否存在于VB.NET中?

检查VB.NET中是否存在Excel对象的好方法是什么?

我知道在VBA中,我可以写下如下的东西:

Sub TestifTableExists(name) as boolean dim exists as range On Error Resume Next Set exists = ActiveSheet.listobject(name).range On Error Goto 0 if exists is nothing TestifTableExists= false else TestifTableExists= true end if end sub 

但现在我正在过渡到VB.NET,并认为在VB.NET中有更好的方法。

在Microsoft.Office.Interop.Excel.Worksheet中有一个ListObjects函数

  Dim wb As Microsoft.Office.Interop.Excel.Workbook Dim ws As Microsoft.Office.Interop.Excel.Worksheet Dim xl As New Microsoft.Office.Interop.Excel.Application wb = xl.Workbooks.Open(FileNameWithPath) ws = wb.ActiveSheet ws.ListObjects(Index As Object)