VBA将Excel导出为XML
2026年09月11日 03:37 发布来源:Excel学习网
以下代码的功能,是配合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引用。
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学习网 [ https://www.excelxxw.com/]
需要保留本文链接地址:https://www.excelxxw.com/jiqiao/2682.html
需要保留本文链接地址:https://www.excelxxw.com/jiqiao/2682.html
上一篇:excel标准差函数
下一篇:返回列表
相关教程:
经典Excel学习视频及教程推荐:
Excel优秀工具推荐:
小工具推荐:
