Vba Excel:是否将Excel工作表导出为XML?
我需要将excel电子表格数据导出为XML。为此,我在工作表中添加了几行代码,即Vba Excel:是否将Excel工作表导出为XML?,xml,excel,vba,Xml,Excel,Vba,我需要将excel电子表格数据导出为XML。为此,我在工作表中添加了几行代码,即 Private Sub Worksheet_Activate() Dim oMyconnection As Connection Dim oMyrecordset As Recordset Dim oMyXML As DOMDocument Dim oMyWorkbook As String Set oMyconnection = New Connection Set oMyrecordset =
Private Sub Worksheet_Activate()
Dim oMyconnection As Connection
Dim oMyrecordset As Recordset
Dim oMyXML As DOMDocument
Dim oMyWorkbook As String
Set oMyconnection = New Connection
Set oMyrecordset = New Recordset
Set oMyXML = New DOMDocument
oMyWorkbook = Application.ThisWorkbook.FullName
oMyconnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & oMyWorkbook & ";" & _
"Extended Properties=excel 8.0;" & _
"Persist Security Info=False"
oMyrecordset.Open "Select * from [Sheet1$A1:C100]", oMyconnection, adOpenStatic
oMyrecordset.Save oMyXML, adPersistXML
oMyXML.Save (ThisWorkbook.Path & "\Output.xml")
oMyrecordset.Close
Set oMyconnection = Nothing
Set oMyrecordset = Nothing
Set oMyXML = Nothing
但是,每当我尝试执行它时,我都会遇到一个错误,比如找不到用户定义的数据类型
。实际上,我得到这个错误是因为行xml作为DOMDocument
。我遗漏了任何参考资料吗?任何帮助都将不胜感激。问题不是“XML输出”本身,而是Microsoft VBA和引用正确的ActiveX组件的奇怪之处
查看其中一个/两个链接,看看它们是否有帮助:
Dim oMyXML As MSXML.DOMDocument
Set oMyXML = New MSXML.DOMDocument
我已经添加了参考
Microsoft ActiveX Data Objects 2.5库
。但同样的错误。我正在使用Excel2010。对于Excel2010,您可能需要ADO 2.6、2.6或更高版本:,并且您需要引用MSXML:是的,我还添加了该引用,我添加了Microsoft ActiveX Data Objects 2.5库,当我尝试添加DAO3.6
引用时,它会给我一个类似加载dll时出错的错误。也许这会有帮助:不,我希望它必须通过vba代码完成,我在单击按钮时使用vba代码。谢谢你的回复。。