Home > Software engineering >  Word VBA won't load MSXML2.DOMDocument object
Word VBA won't load MSXML2.DOMDocument object

Time:06-19

I have some Word VBA code that is supposed to create an Msxml2.DOMDocument object and load an Xml file into it as follows:

Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (XmlFileName)

This code runs perfectly on my computer, but when I try running it on a coworkers computer the Load method fails (returns False and doesn't load the data).

I tried switching from MSXML 3.0 to MSXML 6.0 by changing the first line of code to

Set XDoc = CreateObject("MSXML2.DOMDocument60")

as well as changing the project's reference to v6.0. This resulted in the failure of the code to create the object at all, giving the error message "Runtime error 429: ActiveX component can't create object".

I've also tried reregistering the .dll files for both MSXML versions, with no effect.

If anyone could explain to me what might be causing the code to run on my machine but not on others or how I might resolve the respective errors for either v3.0 or v6.0, it would be greatly appreciated.

CodePudding user response:

I figured out what was causing this problem. The XML file I was trying to load was inside a zip file and before loading it I had to find its name using pattern matching. My coworkers computer had the "File name extensions" checkbox unchecked so the file name that VBA read didn't match the required pattern that included the .xml extension. After I checked the checkbox it worked perfectly.

  • Related