您当前的位置: 首页 > 办公软件教程 > Excel教程 浏览
Excel Vba读取XML
发布时间:2015-10-25    点击率:次    来源:www.sytcke.com    作者:电脑技术学习网

  如下代码示例的功能是,在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

发表留言
发表留言请先登录!
免责声明:本站发布的信息和评论纯属网民个人行为,并不代表本站立场,如发现有违法信息或侵权行为,请直接与本站管理员联系,我们将在收到您的信息后24小时内作出处理!