Excel Vba读取XML
2026年08月22日 17:16 发布来源:Excel学习网
如下代码示例的功能是,在Excel中,通过VBA代码,读取XML文件中的内容。
Dim rst As ADODB.Recordset
Dim stCon As String, stFile As String
Dim i As Long, j As Long
Set rst = New ADODB.Recordset
stFile = "C:dzwebs.xml"
stCon = "Provider=MSPersist;"
With rst
.CursorLocation = adUseClient
.Open stFile, stCon, adOpenStatic, adLockReadOnly, adCmdFile
Set .ActiveConnection = Nothing
End With
With ActiveSheet
For j = 0 To i - 1
.Cells(1, j + 1).Value = rst.Fields(j).Name
Next j
.Range("A2").CopyFromRecordset rst
End With
rst.Close
Set rst = Nothing
Dim rst As ADODB.Recordset
Dim stCon As String, stFile As String
Dim i As Long, j As Long
Set rst = New ADODB.Recordset
stFile = "C:dzwebs.xml"
stCon = "Provider=MSPersist;"
With rst
.CursorLocation = adUseClient
.Open stFile, stCon, adOpenStatic, adLockReadOnly, adCmdFile
Set .ActiveConnection = Nothing
End With
With ActiveSheet
For j = 0 To i - 1
.Cells(1, j + 1).Value = rst.Fields(j).Name
Next j
.Range("A2").CopyFromRecordset rst
End With
rst.Close
Set rst = Nothing
原创文章如转载请注明:转载自Excel学习网 [ https://www.excelxxw.com/]
需要保留本文链接地址:https://www.excelxxw.com/jiqiao/2623.html
需要保留本文链接地址:https://www.excelxxw.com/jiqiao/2623.html
上一篇:excel定位最后一行的四种方法
下一篇:返回列表
相关教程:
经典Excel学习视频及教程推荐:
Excel优秀工具推荐:
小工具推荐:
