以下這段代碼是我系統里匯入匯出模塊的,
可自動識別excel中的數據範圍,并匯入access中
現貼出來與大家分享
FUNCTION Importexcel(inAccesstable as string,inexcelpath as string) AS BEALOON
On Error GoTo Err_inexcel_Click
Dim Address1 As Variant
Dim obj As New Excel.Application
Dim sheettest As Excel.Workbook
Set sheettest = obj.Workbooks.Open(inexcelpath)
Address1 = sheettest.Sheets(1).Range("a1").CurrentRegion.Address(RowAbsolute:=False, ColumnAbsolute:=False)
DoCmd.SetWarnings False
CurrentDb.Execute "DELETE * FROM " & inaccesstable
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, inAccesstable, inexcelpath, True, Address1
DoCmd.SetWarnings True
Importexcel=true
Exit_inexcel_Click:
Exit Sub
Err_inexcel_Click:
MsgBox Err.Description
importexcel=false
Resume Exit_inexcel_Click
End Sub
[此贴子已经被作者于2003-10-20 15:27:17编辑过]
|