Attribute VB_Name = "udf_unicodeEncode" '------------------------------------------------------------------------------- 'File : udf_unicodeEncode.bas ' Copyright mpl by ERB software ' All rights reserved ' wiki.yaslaw.info/dokuwiki/doku.php/vba/functions/unicodedecode 'Environment : VBA 2007 + 'Version : 1.0.0 'Name : unicodeEncode 'Author : Stefan Erb (ERS) 'History : 13.02.2018 - ERS - Creation '------------------------------------------------------------------------------- Option Explicit '/** ' * Wandelt alle Sonderzeichen in Unicode ' * Alles ausser ASCII 32-126 und Leerzeichen ' * @param String ' * @return String ' */ Public Function unicodeEncode(ByVal iString As String) As String Const C_BLACKLIST = "[^\u0020-\u007E\s]" Static rx As Object If rx Is Nothing Then Set rx = CreateObject("VBScript.RegExp"): rx.pattern = C_BLACKLIST unicodeEncode = iString Do While rx.test(unicodeEncode) 'Logik siehe auch http://wiki.yaslaw.info/dokuwiki/doku.php/vba/cast/char2unicode Dim unicode As String: unicode = rx.execute(unicodeEncode)(0).value unicode = Hex(AscW(unicode)) 'Hex-Wert ermitteln unicode = "\u" & String(4 - Len(unicode), "0") & unicode unicodeEncode = rx.replace(unicodeEncode, unicode) Loop End Function