如何将XLS导入到ACCESS中的不同表中去
请问各位,如何将excel按固定的格式导入到ACCESS的不同表中,请高手指点或给点相应的代码!谢谢
Public Sub 将工作簿的所有工作表数据分别保存为不同的数据表()
Dim myData As String, myTable As String
Dim myFile As String, myRange As String
Dim wb As Workbook
Dim ws As Worksheet
Dim myAccess As Access.Application
Set wb = ThisWorkbook
myFile = wb.FullName
myData = wb.Path & "\NewData.mdb"
On Error Resume Next
Kill myData
On Error GoTo 0
Set myAccess = New Access.Application
myAccess.NewCurrentDatabase myData
For Each ws In wb.Worksheets
myTable = ws.Name
myRange = ws.Name & "!" & ws.UsedRange.Address(False, False)
myAccess.DoCmd.TransferSpreadsheet acImport, 8, myTable, myFile, True, myRange
Next
MsgBox "工作簿的各个工作表数据已成功保存到access数据库!", vbOKOnly
myAccess.CloseCurrentDatabase
Set myAccess = Nothing
Set wb = Nothing
Set ws = Nothing
End Sub