体验零代码搭建

Excel Vba读取XML

网友投稿  ·  2024-01-25 16:01  ·  云表格  ·  阅读 589


如下代码示例的功能是,在Excel中,通过VBA代码,读取XML文件中的内容。

如下代码示例的功能是,在Excel中,通过VBA代码,读取XML文件中的内容。

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


excel通过数据模板与vba批量制作csv数据表 << 上一篇
2024-01-25 16:01
Excel表格设置标题跨列居中 动画教程
2024-01-25 16:01
下一篇 >>

相关推荐