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
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