繁体   English   中英

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

[英]Check if an Excel object exists in 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM