|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
正在学习XML,vsto实现相同格式更简单一点。
使用ADO的例子,<s:data>区域和你的要求很接近,元素名不相同。
代码:- Sub xmlDemo()
- '引用ADO 2.8
- Dim strSQL As String
- Dim stCon As String
- Dim rst As New ADODB.Recordset
- Dim str As New ADODB.Stream
- Dim cnn As New ADODB.Connection
-
- stCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties='Excel 12.0;Macro;IMEX=1;HDR=YES';"
- cnn.Open stCon
-
-
- strSQL = "SELECT * FROM [汇总$a2:p200]"
- With rst
- .CursorLocation = adUseClient
- .Open strSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText
- .Save str, adPersistXML
- .Close
- With str
- .SaveToFile "d:\temp\Report.xml", adSaveCreateOverWrite
- .Close
- End With
- End With
- cnn.Close
-
- Set str = Nothing
- Set rst = Nothing
- End Sub
复制代码 |
|