Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring early bound MSXML object throws an error in VBA

I am trying to import xml data into excel.. So the first line of the code is

Dim XMLDOC As MSXML2.DOMDocument

and this gives an error "user defined type not defined"

like image 654
user1486889 Avatar asked Jun 28 '12 13:06

user1486889


People also ask

What is VBA object error?

Object Required in Excel VBA. Object required is an error which is caused at run time when we have defined any variable which is not an object but we try to assign some values using a SET statement. This error is a run time error that arises for various reasons.


2 Answers

Inside the VBE, Go to Tools -> References, then Select Microsoft XML, v6.0 (or whatever your latest is. This will give you access to the XML Object Library.

Updated with fancy pic!

enter image description here

like image 174
Scott Holtzman Avatar answered Sep 21 '22 21:09

Scott Holtzman


I had DOMDocument defined which needed Microsoft XML, v3.0 but I had Microsoft XML, v6.0 selected in references which caused the below error

"user defined type not defined".

The solution

The solution was to either change DOMDocument to DOMDocument60 (60 uses ver 6.0) or use the Microsoft XML, v3.0 reference with DomDocument.


Just a quick note, if anyone is using a different version, such as Microsoft XML, v4.0, then DOMDocument40 should be used. This is because the number at the end of the DOMDocument is specific to the version of the library being used.

like image 31
Joshua Duxbury Avatar answered Sep 17 '22 21:09

Joshua Duxbury