WEB开发网
开发学院软件教学办公软件Excel Excel Vba读取XML 阅读

Excel Vba读取XML

 2012-06-03 09:04:32 来源:开发学院   
核心提示:如下代码示例的功能是,在Excel中,Excel Vba读取XML,通过VBA代码,读取XML文件中的内容

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

Tags:Excel Vba 读取

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接