1

I am trying to take a sheet in Excel and create an XML document using VBA then transform that document using a XSLT stylesheet.

I have included the code below up to the point that I am having problems.

When I try to create an object like so:

Dim transformer As XslCompiledTransform ' transform document

I get this error:

Compile Error: User defined type - not defined

I was previously experiencing this error when defining

Dim objDom As DOMDocument

but referencing this question solved that problem for me. However, I cannot find anything similar for this case.

Can someone explain to me if there is a reference that I need to include and how to find these in the future?

Note: I am using the Visual Basic Editor in Excel 2003 to create this VBA macro

Sub CreateXML()


'Variable to hold all rows in excel file
    Dim rows As Variant

'Variables used to iterate through row array
    Dim i As Integer
    Dim j As Integer

'Create objects for manipulating XML
    Dim objDom As DOMDocument
    Dim objXMLRootelement As IXMLDOMElement
    Dim objXMLelement As IXMLDOMElement
    Dim objXMLattr As IXMLDOMAttribute

'Represents the top level of the XML source
    Set objDom = New DOMDocument

'~~> Creates root element
    Set objXMLRootelement = objDom.createElement("Project")
    objDom.appendChild objXMLRootelement


'~~> Saves XML data to a file
    objDom.Save ("C:\Users\JSLAMKIN\Desktop\test.xml")

'Create an instance of the DOMDocument class:
    Dim xDoc As DOMDocument
    Set xDoc = New DOMDocument

'Create the file as output
    Dim output As DOMDocument
    Dim transformer As XslCompiledTransform ' transform document

...

1 Answer 1

4

XslCompiledTransform is a .NET class and does not appear in the "MSXML, v6.0" library which can be referenced by VBA

Details on how to perform XSLT transformations with the "MSXML, v6.0" library are here

Also, DOMDocument is a synonym for the older DOMDocument30 type from "MSXML, v3.0". The correct type for "MSXML, v6.0" is DOMDocument60. Details on why this is the case are here

Sign up to request clarification or add additional context in comments.

4 Comments

Changing 'Dim objDom As DOMDocument' to 'Dim objDom As DOMDocument60' as you mentioned in your answer causes a compile error. Is this because I am using an older version of MSXML than v3.0 since I am using Excel 2003?
I'm using Excel 2003 and "MSXML, v6.0" is available in the References dialog - that depends more on the version of Windows rather than the version of Office though. As you can see from the linked article on the subject, v6.0 is preferred but v3.0 is also fully supported. Versions earlier than 3.0 have been partially kill-bitted and versions 4 and 5 aren't recommended for use. tl;dr: use v6.0 if you can or v3.0 if you can't, don't use any other version
When I try to add Microsoft XML V6.0 I get the following error: Name conflicts with existing module, project, or object library- Excel hates me.
I restarted Excel and was able to add MSXML, V6.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.