Importing XML Crashes Excel

青春壹個敷衍的年華 提交于 2019-12-22 08:27:15

问题


I have had this recurring problem with all of my spreadsheets for months. The spreadsheet will be working fine and importing the xml files fetched from our website, then all of a sudden it will start crashing everytime on import. The only thing that fixes it is to take all of the contents (sheets, code, references) and drop them into a fresh workbook.

This is the line it crashes on.

ActiveWorkbook.XmlImport URL:=l_strXMLFileName, _
ImportMap:=Nothing, Destination:=Sheets("Imported Data").Range("$A$1")

Has anyone had this problem? If so, is there a better way to keep it from crashing??


回答1:


I posted this question after I found the answer just because this was such a disaster for me, and had plagued me for months. Hopefully this post will keep someone else from pulling their hair out like I did for so long.

The fix is pretty simple. What happens is every time excel imports an xml file, it stores an xmlmap in that spreadsheet. So if you use the same spreadsheet and keep saving it, these build up over time. The best solution I have found is to just delete these xml maps, or reuse the same one (the latter is not a good option many times).

Here is some code to delete all of them (I just run this before the code I included in my question):

Dim XmlMap as XmlMap
    For Each XmlMap In ActiveWorkbook.XmlMaps
        XmlMap.Delete
    Next



回答2:


Is there a chance the input XML has some illegal / unescaped characters?



来源:https://stackoverflow.com/questions/1002663/importing-xml-crashes-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!