-2

In a previous post I was looking to find a way to manipulate XML, and an answer was provided by David that looked very promising. However, I have been having a small issue when it comes to the following line:

Set Entity = DOM.DocumentElement.getElementsByTagName("EntityId")(0)

where by EntityId I actually meant entityId (to preserve continuity I have left the code as is).

Namely I get the following error: Object variable / with block variable not set.

Now, I found this post, which outlined a potential solution, but I have the MSXML 6.0 reference box checked. I have also confirmed, as that poster did, that the tag does exist in the XML document I am referencing. Is there another reason this could be happening outside of user error?

EDIT: Screenshot of entityId:

enter image description here

Community
  • 1
  • 1
114
  • 876
  • 3
  • 25
  • 51

1 Answers1

1

The only way I can replicate your error is by making an XML file which is invalid/doesn't parse.

Your XML file is broken. Fix it, and the code will work.

Put a breakpoint on the Set entity line, and then examin the DOM.parseError in the Locals window.

enter image description here

This will indicate whether there are problems with your XML file that prevent it from parsing.

When the xml file cannot be parsed, the DOM.DocumentElement is Nothing, and that will raise the Object Required error.

David Zemens
  • 53,033
  • 11
  • 81
  • 130
  • Unfortunately parseError shows errorCode 0, and documentElement contains child nodes. However, documentElement does describe 'definition' as 'Nothing' - could that be the issue? – 114 May 14 '14 at 20:23
  • Hmm I don't think that's ir but can you add a screenshot showing that? And you could try skipping to the lines to print the new file without making any "changes" I would be curious to see whether it will print the xml before any changes... – David Zemens May 14 '14 at 21:48
  • It's OK if the definition is "nothing" (that's what I see too), but the object itself is not `Nothing`. If you see there are child nodes to the `DocumentElement`, first step to troubleshoot would be to start picking through those and see where they take you -- can you navigate through that tree and find the "entityID" node(s)? – David Zemens May 15 '14 at 02:58
  • I found entityId under a child node - I'll update my post with a screenshot. – 114 May 15 '14 at 15:09
  • Are you still doing `Set Entity = DOM.DocumentElement.getElementsByTagName("EntityId")(0)`??? – David Zemens May 15 '14 at 15:32
  • No, I revised to entityId (and entity) but left the original code with an explanation since Tim pointed out the EntityId issue and it would make that comment confusing if I modified the code in the question. – 114 May 15 '14 at 16:04
  • Yeah that should not matter... I don't suppose there's any way you can send the file to me? Without the file, it's really impossible to assist any further. – David Zemens May 15 '14 at 16:11
  • It should be possible to send the sample XML file that I am using at some point. – 114 May 15 '14 at 17:35