Import XML via VBA

Rinse04

New Member
Joined
May 19, 2020
Messages
18
Office Version
  1. 2019
Platform
  1. Windows
I am trying to modify a filedialog I currently use to import xml files. I would like to change from the folder selection to individual file selection, but I cannot seem to get it to work for me.

If possible could somebody please help me? Or point me in the right direction. Thank you.

Sub XMLtoExcel()
Dim xWb As Workbook
Dim xSWb As Workbook
Dim xStrPath As String
Dim xFileDialog As FileDialog
Dim xfile As String
Dim xCount As Long
Dim myURL As String
Dim n As Long
Set xFileDialog = Application.FileDialog(msoFileDialogFilePicker)
xFileDialog.InitialFileName = "C:\"
xFileDialog.AllowMultiSelect = True
xFileDialog.Title = "Select a file"
If xFileDialog.Show = -1 Then
xStrPath = xFileDialog.SelectedItems(1)
End If
If xStrPath = "" Then Exit Sub
Application.ScreenUpdating = False
Set xSWb = ThisWorkbook

xfile = Dir(xStrPath & "\*.xml")
Do While xfile <> ""
myURL = xStrPath & "\" & xfile
ImportToxml myURL, xSWb

xfile = Dir()
Loop
Application.DisplayAlerts = False
Application.ScreenUpdating = True
Exit Sub
End Sub

Sub ImportToxml(myURL As String, Wb As Workbook)

Dim myMap As XmlMap
Set myMap = Wb.XmlMaps(1)
myMap.Import Url:=myURL, Overwrite:=False

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,826
Messages
6,121,795
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top