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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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