|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
给二段代码,一个是ACCESS文件的多文件合并,支持子目录遍历,另一段是EXCEL导入ACCESS的代码,自己参考着改一下即可:
Function Getfd(path, FileName As String) As Integer
On Error GoTo Err:
Dim FileStr$, i&
Set Fso = CreateObject("scripting.filesystemobject")
Set ff = Fso.getfolder(path)
For Each f In ff.Files
FileStr = LCase(f.Name)
If ((FileName <> f.Name) And ("~$" & FileName <> f.Name) And ((Right(FileStr, 6) = ".accde") Or (Right(FileStr, 6) = ".accdb") Or (Right(FileStr, 4) = ".mdb"))) Then
FileStr = Replace(path + "\" + f.Name, "\\", "\")
DoCmd.RunSQL "insert into 表名 select * from [" & FileStr & "].表名"
End If
Next f
'遍历子目录
For Each fd In ff.subfolders
i = Getfd(fd, FileName)
Next fd
Set Fso = Nothing
Exit Function
Err:
MsgBox FileStr & "出错"
End Function
将EXCEL表导入到现有表中:
Insert INTO ABC Select * FROM [EXCEL 12.0 XML;DATABASE=E:\temp\text.xlsx].sheet1;
|
|