' 核心逻辑:遍历文件夹,静默导入 XMLSub BatchImportInvoices() Dim strPath As String, strFile As String Dim xmlDoc As New MSXML2.DOMDocument60 Dim rs As New ADODB.Recordset ' 1. 设置路径 strPath = "C:\发票归档\" strFile = Dir(strPath & "*.xml") ' 2. 连接 Access 数据表 rs.Open "发票主表", CurrentProject.Connection, adOpenKeyset, adLockOptimistic Do While strFile <> "" xmlDoc.async = False If xmlDoc.Load(strPath & strFile) Then rs.AddNew ' 提取 XML 节点,填入数据库字段 On Error Resume Next rs!发票号 = xmlDoc.SelectSingleNode("//InvoiceNumber").Text rs!总金额 = xmlDoc.SelectSingleNode("//TotalTax-includedAmount").Text rs!日期 = xmlDoc.SelectSingleNode("//IssueTime").Text On Error GoTo 0 rs.Update End If strFile = Dir ' 找下一个 Loop rs.Close MsgBox "导入成功!"End Sub