首页 > 办公 > Excel > 正文

VBA将Excel导出为XML

2019-10-25 20:23:22
字体:
来源:转载
供稿:网友

  以下代码的功能,是配合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读取XML

下一篇:VBA代码编写技巧

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表