您当前的位置: 首页 > 办公软件教程 > Excel教程 浏览
VBA将Excel导出为XML
发布时间:2015-10-25    点击率:次    来源:www.sytcke.com    作者:电脑技术学习网

  以下代码的功能,是配合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引用。

发表留言
发表留言请先登录!
免责声明:本站发布的信息和评论纯属网民个人行为,并不代表本站立场,如发现有违法信息或侵权行为,请直接与本站管理员联系,我们将在收到您的信息后24小时内作出处理!