如何解决将具有类似结构的多个XML文件导入具有相同表的Access DB中
我研究并获得了从本地路径向Access数据库表导入多个XML文件的代码。我打算添加一个延迟计时器,以免在桌面导入速度太慢的情况下避免每个XML文件之间发生合谋。
Private Sub Command2_Click()
Dim fs
Dim fsFolder
Dim fsFile
Dim i As Double
Set fs = CreateObject("scripting.filesystemobject")
Set fsFolder = fs.getfolder("C:\MyDesiredPath")
For Each fsFile In fsFolder.files
Debug.Print fsFile.Name
Application.ImportXML fsFile.Path,acStructureAndData
i = Timer + 0.5
While Timer < i
DoEvents
Wend
Next fsFile
End Sub
根据此代码,如果共享路径中有100个XML文件,则在导入XML文件后将在数据库中产生100个表。但是,我的目标是将所有这100个XML文件放入一个表中。由于它们具有相同的结构,我认为这是可能的。有人可以帮助我提供正确的代码吗?
非常感谢您!
解决方法
Private Sub Import_XML()
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim strPath As String ' Path to file folder
'strPath = Me![Path]
strPath = "C:\XML\"
strFile = Dir(strPath & "*.XML")
strFile = Dir(strPath & A)
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
Exit Sub
End If
'cycle through the list of files
For intFile = 1 To UBound(strFileList)
Application.ImportXML strPath & strFileList(intFile),2
Next intFile
MsgBox "Import Completed"
End Sub
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。