0
I’m completely new in vba and I’m having a problem with my code.
I need to extract data from some tags from various files XML. When I execute the code or perform Debub, the error of 424 "The object is required" on the line XML.Filename = fd.SelectedItems(i)
.
Here is the code:
Private Sub CommandButtonImport_Click()
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Title = "Select Multiple XML Files"
.Filters.Add "XML File", "*.xml", 1
.AllowMultiSelect = True
If .Show = True Then
Dim xdoc As Object
Set xdoc = CreateObject("MSXML2.DOMDocument")
xdoc.async = False: xdoc.validateOnParse = False
row_number = 1
For i = 1 To .SelectedItems.Count
XML.Filename = fd.SelectedItems(i)
xdoc.Load (XML.Filename)
Set Products = xdoc.DocumentElement
For Each Product In Products.ChildNodes
Application.Range("ProductsRange").Cells(row_number, 1).Value = Product.ChildNodes(0).Text
Application.Range("ProductsRange").Cells(row_number, 2).Value = Product.ChildNodes(1).Text
Application.Range("ProductsRange").Cells(row_number, 3).Value = Product.ChildNodes(2).Text
Application.Range("ProductsRange").Cells(row_number, 4).Value = Product.ChildNodes(3).Text
Application.Range("ProductsRange").Cells(row_number, 5).Value = Product.ChildNodes(4).Text
Application.Range("ProductsRange").Cells(row_number, 6).Value = Product.ChildNodes(5).Text
Application.Range("ProductsRange").Cells(row_number, 7).Value = Product.ChildNodes(6).Text
row_number = 1 = row_number + 1
Next Product
Next i
End If
End With
End Sub