クエリの結果を取得する
Sub クエリデータ取得1()
Dim myCon As ADODB.Connection, myRS As ADODB.Recordset, FileName As String
Set myCon = New ADODB.Connection
Set myRS = New ADODB.Recordset
FileName = ThisWorkbook.Path & "\mdb\2-sampleDB.mdb"
myCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName
With myRS
.ActiveConnection = myCon '使用する接続を指定
.Source = "Q_伝票作成" '取り込みたいクエリを指定
.Open
End With
Range("A1").CopyFromRecordset myRS
myRS.Close: Set myRS = Nothing
myCon.Close: Set myCon = Nothing
End Sub
使用するクエリ
実行結果

