我需要将 excel 电子表格数据导出到 XML。为此,我在 WorkSheet_Activate 中添加了几行代码,即
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
但是,当我尝试执行它时,我会收到类似User-Defined Datatype not found
. 实际上我因为这条线而收到这个错误Dim oMyXML As DOMDocument
。我缺少任何参考吗?任何帮助将不胜感激。