Code Snippet "VBA Access"
Textdokument von Unicode UTF8 zu Unicode (LittleEndian) konvertieren
Das Problem ist, dass dies unter Word 2000 (W9) und Word 2003 anders gemacht wird
Public Sub convertutf8tounicode(ByVal straltpath As String, ByVal strnewpath As String)
Dim objAppWord 'As Word.Application
Set objAppWord = CreateObject("Word.Application")
If CLng(objAppWord.Version) > 9 Then
objAppWord.Documents.Open FileName:=straltpath, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=Word.wdOpenFormatAuto, XMLTransform:="", _
Encoding:=65001
'Achtung: Ab Word XP wird das Format beim Speichern mit Encoding=1200 festgelegt
objAppWord.ActiveDocument.SaveAs FileName:=strnewpath, FileFormat:=Word.wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=False, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1200, InsertLineBreaks:=False, AllowSubstitutions:=False, _
LineEnding:=Word.wdLFOnly
Else
'Word 2000 oder tiefer
objAppWord.Documents.Open FileName:=straltpath, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
' .wdFormatUnicodeText
'Achtung: In Word 2000 wird das Format vor dem Speichern in Eigenschaft SaveEncoding festgelegt
objAppWord.ActiveDocument.SaveEncoding = 1200 ' msoEncodingUnicodeLittleEndian
objAppWord.ActiveDocument.SaveAs FileName:=strnewpath, FileFormat:= _
Word.wdFormatEncodedText, LockComments:=False, Password:="", _
AddToRecentFiles:=False, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
End If
objAppWord.ActiveDocument.Close
End Sub