|
▼sakaiII さん:
おはようございます。
※要参照設定 Excel x.x Object Library
Sub 範囲指定取込()
Dim xlsApp As New Excel.Application
Dim xlsWkb As Workbook
Dim xlsSht As Worksheet
Dim xName As String 'Excelブックのフルパス名
Dim xSheet As String '取り込むシート名
Dim Kiten As Range
Dim EndCell As String
xName = "C:\test.xls"
xSheet = "Ken"
Set xlsWkb = xlsApp.Workbooks.Open(xName)
Set xlsSht = xlsWkb.Worksheets(xSheet)
Set Kiten = xlsSht.Range("B5")
EndCell = xlsSht.Cells(Kiten.END(xlDown).Row, _
Kiten.END(xlToRight).Column).Address(False, False)
Set Kiten = Nothing
Set xlsSht = Nothing
xlsWkb.Close: Set xlsWkb = Nothing
xlsApp.Quit: Set xlsApp = Nothing
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"T_範囲取込", xName, True, xSheet & "!B5:" & EndCell
End Sub
取込元のExcelファイルや取込先のテーブルの存在チェックなどは行っていません。
|
|