Skip to content

Instantly share code, notes, and snippets.

@neelsg
Created November 3, 2014 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neelsg/eae9aacde4ec0a2f184b to your computer and use it in GitHub Desktop.
Save neelsg/eae9aacde4ec0a2f184b to your computer and use it in GitHub Desktop.
Functions to decode or encode text for use in an XML file. VBScript / VBA
Public Function DecodeXml(TextToDecode As String) As String
'Take text that has been encoded for XML and change it to normal text
Dim Res As String
Res = Replace(Replace(Replace(Replace(TextToDecode, "&quot;", """"), "&gt;", ">"), "&lt;", "<"), "&amp;", "&")
DecodeXml = Res
End Function
Public Function EncodeXml(TextToEncode As String) As String
'Take text and change special chars so that it can be included in an XML file
Dim Res As String
Res = Replace(Replace(Replace(Replace(TextToEncode, "&", "&amp;"), ">", "&gt;"), "<", "&lt;"), """", "&quot;")
EncodeXml = Res
End Function
@pinchukd
Copy link

you forgot replace single quote ' to '

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment