Replace special characters for XML
If you are writing custom function for XML export – do not forget to replace predefined XML characters, else XML parsing function may fail. There are only 5 characters, so function looks pretty simple:
Function XMLSpecialChars(ByVal varText As Variant) As String
varText = varText & ""
varText = Replace(varText, "&", "&")
varText = Replace(varText, "'", "'")
varText = Replace(varText, """", """)
varText = Replace(varText, ">", ">")
varText = Replace(varText, "<", "<")
XMLSpecialChars = varText
End Function
Labels: VBA