I am trying to print an XML file with contents from several cells. The XML file needs a beginning and end wrapper, however the end wrapper is never appearing.
Here is the code I wrote
The last line of the file should be "</promotions>", but this never seems to actually be written in the file.
Edit: When I checked the file again after ~10 minutes, the last line DOES appear. But it seems to require a few minutes to actually be written in. Notepad++ notified me that the file was changed and needed to be reloaded. Not sure why it takes so long to write this last line.
Here is the code I wrote
VBA Code:
Dim XMLFile As Integer, FilePath As Variant
FilePath = Application.GetSaveAsFilename(InitialFileName:=Format(Date, "yyyy-m-d") & "_Promotion_Import", FileFilter:="Xml (*.xml), *.xml")
If FilePath = False Then Exit Sub
XMLFile = FreeFile
Open FilePath For Output As XMLFile
Print #XMLFile, "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbNewLine & "<promotions xmlns=""http://www.demandware.com/xml/impex/promotion/2008-01-31"">"
CurrentRow = 2
With Worksheets("XML Output")
Do While CurrentRow <= 5
Print #XMLFile, .Range("A" & CurrentRow)
Print #XMLFile, .Range("B" & CurrentRow)
CurrentRow = CurrentRow + 1
Loop
End With
Print #XMLFile, "</promotions>" 'This is the line that should be printed, but is not
Close TextFile
The last line of the file should be "</promotions>", but this never seems to actually be written in the file.
Edit: When I checked the file again after ~10 minutes, the last line DOES appear. But it seems to require a few minutes to actually be written in. Notepad++ notified me that the file was changed and needed to be reloaded. Not sure why it takes so long to write this last line.