首页 excel技巧 Excel Vba读取XML

Excel Vba读取XML

发布:2023-08-06 15:21:11 阅读:116

如下代码示例的功能是,在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代码 下一篇:excel随机大小写字母.固定长度的字母
相关文章 查看更多