|
本帖最后由 cgsilicone 于 2013-6-22 15:31 编辑
你的附件我的版本打不开。不用很复杂的知识,你的代码略微修改,直接就存入数据库中了(不需要二维数组),代码如(经测试有效)下:
Private Sub Command0_Click()
Set EXCEL的功能 = CreateObject("EXCEL.Application")
EXCEL的功能.Visible = True
FileName = EXCEL的功能.GetOpenFilename("txt,*.txt", , "select", , False)
EXCEL的功能.Quit
Set 数据表 = CurrentDb.OpenRecordset("表1", dbOpenDynaset)
Open FileName For Input As #1
aa = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
m = 0
For i = 5+1 To UBound(aa)
If Len(Trim(aa(i))) < 50 Then GoTo L1
If InStr(aa(i), "-------") > 0 Then GoTo L1
If InStr(aa(i), "Custname") > 0 Then GoTo L1
数据表.AddNew
数据表.Fields(0) = Trim(Left(aa(i), 45))
数据表.Fields(1) = Trim(Mid(aa(i), 46, 26))
数据表.Fields(2) = Trim(Mid(aa(i), 73, 26))
数据表.Fields(3) = Trim(Mid(aa(i), 100, 38))
数据表.Fields(4) = Trim(Mid(aa(i), 139, 25))
数据表.Update
m = m + 1
L1: Next
数据表.Close
Set 数据表 = Nothing
MsgBox "导入数据成功,共导入" & m & "条"
End Sub
|
|