Excel Vba读取XML

2013-09-01 15:29 阅读 501 次 评论关闭

如下代码示例的功能是,在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读取XML | 猎微网
分类:Excel VBA 标签:, , ,

评论已关闭!