Option Explicit ----------------------------------------------------------------- Sub 当月仕入データを取得する() 'Excel 2007バージョンのファイルの取得 'Microsoft ActiveX Data Objects 2.1 Library 以上 2.8は不可 'ツール - 参照設定にてチェックを付ける。 Dim Cnn As ADODB.Connection Dim Rec As ADODB.Recordset Dim intMon As Integer Worksheets("当月仕入").Select Range("B4:H100").ClearContents Set Cnn = New ADODB.Connection Cnn.Provider = "Microsoft.ACE.OLEDB.12.0" 'Excel97,2000のブックはExcel8.0で設定する Cnn.Properties("Extended Properties") = "Excel 12.0" Cnn.Open "E" & ":" & "\" & "当月仕入データファイル.xlsm" Set Rec = New ADODB.Recordset Set Rec.ActiveConnection = Cnn Rec.Open "[当月仕入$B2:H100]", , adOpenKeyset, adLockPessimistic, adCmdTable Worksheets("当月仕入").Range("B2").CopyFromRecordset Rec Rec.Close Cnn.Close Set Rec = Nothing Set Cnn = Nothing End Sub