MS Excell シート名列挙

広告

広告

解説

アクセスからエクセルを操作するときに、今あるシート名を列挙できたら良いなと。

ソース

Dim DB As Database
Dim Exl As String
Dim Tbl As TableDef
Dim strText As String
Dim l As Long

Exl = "エクセルフルパス"
l = 1

Set DB = OpenDatabase(Exl, False, False, "Excel 8.0;HDR=NO;")

For Each Tbl In DB.TableDefs
    If Tbl.Attributes And dbSystemObject Then
    Else
        If l = 1 Then
            strText = Tbl.Name
            l = 0
        Else
            strText = strText & "; " & Tbl.Name
        End If
    End If
Next Tbl

DB.Close
Set DB = Nothing
strText = Replace(strText, "$", "")
Me.strExSheet.RowSource = strText    'リストボックスに結果を放り込んだり…

広告

Copyright (C) 2003-2006 七鍵 key@do.ai 初版:2003年07月07日 最終更新:2006年08月08日