Dzwebs.Net

撰写电脑技术杂文十余年

Excel Vba读取XML

Admin | 2012-2-3 10:47:26 | 被阅次数 | 12113

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

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

上一篇:SUMSQ平方和函数

下一篇:VBA将Excel导出为XML

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计