首页 > 办公 > Excel > 正文

Excel Vba读取XML

2024-08-23 19:53:39
字体:
来源:转载
供稿:网友

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表