Sub AccessデータベースをPowerQueryで読み込む()
    Dim filePath As String
    Dim mLines As Variant
    Dim mCode As String
    Dim ws As Worksheet
    Dim lo As ListObject

    filePath = ThisWorkbook.Path & "\Accessデータベース.accdb"

    mLines = Array( _
        "let", _
        "    ソース = Access.Database(", _
        "        File.Contents(""" & filePath & """)", _
        "    ),", _
        "    一月明細 = ソース{[Schema="""", Item=""1月明細""]}[Data],", _
        "    二月明細 = ソース{[Schema="""", Item=""2月明細""]}[Data],", _
        "    結合 = Table.Combine({一月明細, 二月明細})", _
        "in", _
        "    結合" _
    )

    mCode = Join(mLines, vbCrLf)

    ThisWorkbook.Queries.Add _
        Name:="PQ接続", _
        Formula:=mCode

    Set ws = ActiveSheet

    Set lo = ws.ListObjects.Add( _
        SourceType:=0, _
        Source:="OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=PQ接続;Extended Properties="""";", _
        Destination:=ws.Range("A1"))

    With lo.QueryTable
        .CommandType = xlCmdSql
        .CommandText = "SELECT * FROM [PQ接続]"
        .Refresh BackgroundQuery:=False
    End With

    lo.Name = "T_Access"

    ThisWorkbook.Queries("PQ接続").Delete
End Sub
