How to fetch data from XML file to Excel sheet using VBA How to fetch data from XML file to Excel sheet using VBA vba vba

How to fetch data from XML file to Excel sheet using VBA


Sub ImportXMLtoList()Dim strTargetFile As StringDim wb as Workbook     Application.Screenupdating = False     Application.DisplayAlerts = False     strTargetFile = "C:\example.xml"     Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)     Application.DisplayAlerts = True     wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Sheet2").Range("A1")     wb.Close False     Application.Screenupdating = TrueEnd Sub


i created a simply xmlmap. I need a code to import xml data to excel ( right click-xml-import), to get data from an xml, or another. I want to keep the xmlmap that I created, and just replace the data in my xlxs to data from another xlm.

'Select the fileFname = Application.GetOpenFilename(FileFilter:="xml files (*.xml), *.xml", MultiSelect:=False)'Check if file selectedIf Fname = False Then    Exit Sub    ElseWorkbooks.Open Filename:=FnameEnd If