0

I ran into an issue with using the XML files. I have a macro that searches thought the nodes inside the XML file and the macro is running fine until I restart my laptop. Every time it will go into error and I first have to open an XML file manually with Microsoft XML notepad and then it`s working again. Can I solve this without changing the default opening program on the laptop itself?

    Set oXMLFile = CreateObject("Microsoft.XMLDOM")
    XMLFileName = Dir(MAIN_FOLDER & "\" & LotAppendix & "*.xml")
    oXMLFile.Load (XMLFileName)

1 Answer 1

2

Most likely your problem is one of just passing the filename to Load() - that will work if the current directory is set to MAIN_FOLDER (as for example it will be if you navigate there and manually open a file) but will fail if it's not.

The fix is to always use the full path and never rely on a specific current directory being set:

Set oXMLFile = CreateObject("Microsoft.XMLDOM")
XMLFileName = Dir(MAIN_FOLDER & "\" & LotAppendix & "*.xml")
oXMLFile.Load MAIN_FOLDER & "\" & XMLFileName
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this works but I don`t understand. In the end the file path is: MAIN_FOLDER \ MAIN_FOLDER \ LotAppendix. How come it still works if the folder path is double?
Dir() only returns the file name, not the full path.

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.