我以前做過這個。您將需要逐行打印XML。使用FileSystemObject創建一個空白的.xml文件。然後打開.xml作爲輸出。接下來構建您的.xml字符串並將其輸出到輸出。
Dim fs as Object
Dim strWriteFileName , strWriteLine as string
Set fs = CreateObject("Scripting.FileSystemObject")
strWriteFileName = Forms!MAIN.OutputFile.value & ".xml"
Open strWriteFileName For Output As #1
strWriteLine = "<?xml version=""1.0"" encoding=""utf-8""?>"
Print #1, strWriteLine
strWriteLine = "<Root Name=""scenario"">"
Print #1, strWriteLine
strWriteLine = "<Entries>"
Print #1, strWriteLine
'Depending on XML schema here may be a good place for a Loop'
strWriteLine = "<Entry Name=""firstname"" Value=""gedaan"" />"
Print #1, strWriteLine
strWriteLine = "<Entry Name=""lastname"" Value=""salame"" />"
Print #1, strWriteLine
strWriteLine = "<Entry Name=""job"" Value=""Engineer"" />"
Print #1, strWriteLine
'And here may be a good place to end the loop'
strWriteLine = "</Entries>"
Print #1, strWriteLine
strWriteLine = "</Root>"
Print #1, strWriteLine
Close #1
set fs = Nothing
這將打印您上面的內容。如果您需要添加多個條目,只需循環打印更多名稱即可。我還使用了一個名爲MAIN的表單和一個名爲OutputFile的文本框,因此可以隨意將它們替換爲您需要的。
非常感謝。 – Gedaan