工作簿名称表名称

function GetSheetNames(sWorkbook)
    Dim objConn,objCat,tbl,iRow,sConnString,sTableName ,dotpos
    'sWorkbook工作簿名称及路径.
    sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sWorkbook & ";Extended Properties=Excel 8.0;"
    Set objConn = CreateObject("ADODB.Connection")
    objConn.Open sConnString
    Set objCat = CreateObject("ADOX.Catalog")
    Set objCat.ActiveConnection = objConn

    iRow = 1
    For Each tbl In objCat.Tables
        sTableName = tbl.Name
    Next
    objConn.Close
    Set objCat = Nothing
    Set objConn = Nothing
 dotpos=instr(sTableName,"$")
 GetSheetNames=left(sTableName,dotpos-1)
End function

posted @ 2010-11-12 13:16  龙圆  阅读(284)  评论(0编辑  收藏  举报