Properties コレクションを使用して接続
Sub Excelに接続3()
Dim myCon As New ADODB.Connection, FileName As String
'接続先のExcelファイル
FileName = ThisWorkbook.Path & "\xls\DataBook.xls"
'Propertiesコレクションを使用する
With myCon
'Access(Jes)と同じOLE DB プロバイダを使用
.Provider = "Microsoft.Jet.OLEDB.4.0"
'初期設定として、Excelファイルへの接続を指定
.Properties("Extended Properties") = "Excel 8.0"
'対象ブックに接続
.Open FileName
End With
MsgBox "Excelブックに接続完了!"
'接続を解除し、オブジェクトをクリア
myCon.Close: Set myCon = Nothing
End Sub
