Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Loading xml files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Archer - 20 May 2006 16:41 GMT
Hello - I have had luck loading xml files using the following declaration and
assignment in the sub routine:

   Set xmlDoc = CreateObject("Microsoft.XMLDOM")
   xmlDoc.async = "false"
   xmlDoc.Load ("G:\CatTree.xml")

However, I have downloaded a sample excel file that makes the following
declaration in the declarations section of the module:

  Dim catTree As MSXML2.DOMDocument

And later in the sub routine, the file is loaded with the following code:

  Set catTree = New Msxml2.DOMDocument
  catTree.async = False
  catTree.Load (catTreeFileLocation)

What is the difference between the two ways of handling xml.  The reason I
ask is that the 2nd example works just fine in the excel file that I
downloaded.  But if I try to duplicate in any other file, I get a compile
error:  "User-defined type not defined."  at the module level declaration.  
What could be the difference between the file I downloaded and a file I
create myself?  I'm talking about duplicating the whole project so that there
is no difference... I still get the compile error.
Signature

Thanks,
Mike

Tom Ogilvy - 20 May 2006 17:36 GMT
It sounds like the error is caused because you have not created a reference
to the library that defines MSXML2

in the workbook that workds, go into the VBE and with that workbook as the
activeproject in the vbe (selected in the project explorer window), go into
Tools=>References.   You should see a reference to Microsoft XML, ver x.x

where x.x will be the version number.   Then you can go to the object
browser and select MSXML2 and see the objects such as DOMDocument.

So in your other applications, you will need to set the reference to use the
second approach.  The first approach you show is called late binding and
avoids the need to set the reference.

Signature

Regards,
Tom Ogilvy

> Hello - I have had luck loading xml files using the following declaration and
> assignment in the sub routine:
[quoted text clipped - 21 lines]
> create myself?  I'm talking about duplicating the whole project so that there
> is no difference... I still get the compile error.
Mike Archer - 20 May 2006 18:04 GMT
Great!  That works now.  BTW - Are there any disadvantages to using the late
binding approach?  I like not having to worry about setting the library
reference.
Signature

Thanks,
Mike

> It sounds like the error is caused because you have not created a reference
> to the library that defines MSXML2
[quoted text clipped - 37 lines]
> there
> > is no difference... I still get the compile error.
Tom Ogilvy - 20 May 2006 18:34 GMT
It is slower and in development, you don't get intellisense.   However, it
isn't a lot slower.

A lot of people use early binding for development, then switch to late
binding for distribution to avoid version problems with library references.

Signature

Regards,
Tom Ogilvy

> Great!  That works now.  BTW - Are there any disadvantages to using the late
> binding approach?  I like not having to worry about setting the library
[quoted text clipped - 41 lines]
> > there
> > > is no difference... I still get the compile error.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.