Sub ImportXLS(XLSName As String, ShName As String, TblName As String)
'---------------------------------------------------------------------------------------
' Procedure : ImportXLS
' DateTime : 2013-10-12 09:32
' Author : 叶海峰
'XLSName Excel源文件名,包含路径和"\"号
'ShName'Excel源文件中需要导入的工作表名称
'TblName 数据库中导入的目标表名称
'作用:导入带alt+回车的单元格数据到mdb的字段中,保持分行显示
Dim rst As DAO.Recordset
Dim xlapp As Object
Dim i As Long
Dim j As Long
Dim str
Set xlapp = CreateObject("excel.application")
Set rst = CurrentDb.OpenRecordset(TblName)
CurrentDb.Execute "delete * from " & TblName '清空目标表
With xlapp
.workbooks.Open (XLSName)
.sheets(ShName).select
For i = 2 To .activesheet.usedrange.rows.Count
rst.AddNew
For j = 1 To .activesheet.usedrange.columns.Count
If InStr(1, .cells(i, j), Chr(10)) > 0 Then
str = Replace(.cells(i, j), Chr(10), vbCrLf)
Else
str = .cells(i, j)
End If
rst(j - 1) = str
Next
rst.Update
Next
xlapp.Quit
End With
Set xlapp = Nothing
rst.Close
Set rst = Nothing
End Sub
Sub BB()
Call AA(CurrentProject.Path & "\信息.xls", "1A", "AAA")
End Sub