EXCEL VBA:将Excel导出为XML

2013-08-30 17:02 阅读 574 次 评论关闭

以下代码的功能,是配合select,将Excel导出为XML文件

Const stSQL As String = "SELECT * FROM [Report]"
Dim stCon As String
stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"";"

Dim rst As New ADODB.Recordset

Dim str As New ADODB.Stream

With rst

.CursorLocation = adUseClient
.Open stSQL, stCon, adOpenStatic, adLockReadOnly, adCmdText
.Save str, adPersistXML
.Close

With str
.SaveToFile "C:\dzwebs.xml", adSaveCreateOverWrite
.Close
End With

End With

Set str = Nothing
Set rst = Nothing

注意,要使用如上的代码,需要添加MS ADO Library引用。

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:EXCEL VBA:将Excel导出为XML | 猎微网
分类:Excel VBA 标签:, , ,

评论已关闭!