简体   繁体   中英

In Excel-VBA .how to save a xml file in the existing sheet without saving it any drives

Please check below code... Here I dont want converted xml code to save in any drive, Instead I want to put the contents of converted file into the next sheet of existing excel.

Sub GenerateXML()
'
' GenerateXML Macro
'

'
    Sheets("Sheet2").Select
    ActiveWorkbook.XmlMaps("result_Map").Export URL:="D:\temp3.xml"
    Sheets.Add After:=Sheets(Sheets.Count)
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;D:\temp3.xml", Destination:=Range("$A$1"))
        .Name = "temp3"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 1252
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(2, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
  '  Kill "C:\temp.xml"
End Sub

Instead of using XmlMaps.Export method, msdn says the following:

Use the ExportXml method to export the contents of the mapped cells to a String variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM