PDA

View Full Version : Import XML to worksheet with mapped schema



Kamdrz
05-31-2021, 11:25 AM
Hello All,

I'm new over the board and I couldn't find a topic with identical problem. Please forgive me if there were several of these.

So I have a simple workbook that I use to search a specific data from XML files. Up till now, I used VBA to simply import the entire XML file, with a lot of data i didn't need and I had to extract the necessary columns to another sheet first.

However, today I learned that I can map from schema what I exactly need, which makes my workbook easier to use and much more accurate.

As great as it sounds, I have no issues to import XML files from Developer tab, but sadly my VBA cannot perform this operation. And this is regardless if I use schema name ("Manifest") or not.


Sub DoryRules()

Dim FileDialog As Office.FileDialog
Dim XMLLocation As String

Set FileDialog = Application.FileDialog(msoFileDialogFilePicker)
With FileDialog
.AllowMultiSelect = False
.Title = "Select Maniefest XML"
.Filters.Add "Manifest", "*.xml", 1
.InitialFileName = Application.ActiveWorkbook.Path
If .Show <> 0 Then
XMLLocation = .SelectedItems(1)
Else
MsgBox "Manifest XML has not been selected."
End
End If
End With

ActiveWorkbook.XmlImport URL:=XMLLocation, ImportMap:=Nothing, Overwrite:=False, Destination:=Range("$A$3")

End Sub

The errors I'm receiving are as follows:

Run-time error '1004':

The operation cannot be completed because the XML table is bound to a different XML map.
That's when I use the primary code - changing override option has the same result.


Compile error: Type mismatch
That's when I use the schema name at importmap.

I tried to make research as I always do, but couldn't find solution. I'm also fresh when it comes to VBA.

Can I count on some help? Cheers.