'How to convert Outlook messages to text maintaining double-byte character set?
I have a code to convert outlook emails into text. Works great except for emails received with DBCS (double-byte character set) from CJK (Chinese/Japanese/Korean) languages.
The code I have is as follows:
Sub SaveAsTXT(myMail As Outlook.MailItem)
Dim objItem As Object
Dim myFolder As Folder
' Get sender email address
senderEmAddress = myMail.Sender.GetExchangeUser().PrimarySmtpAddress
If Not TypeName(myItem) = "Nothing" Then
strname = myMail.Subject
strdate = Format(myMail.ReceivedTime, "yymmddhhmmss")
myMail.SaveAs "C:\folder\" & strdate & ".txt", olTXT
End If
End Sub
I need to keep the extract as text. If I copy the email manually into notepad the CJK characters are copied correctly and saved correctly if I use UTF-8.
What can I add in the VBA code to capture the CJK characters correctly?
Solution 1:[1]
You can read the MailItem.Body
property (like all COM strings, it is UT-16), explicitly build the header, combine it with the message body, and save the file yourself.
If using Redemption (I am its author) is an option, its version of SaveAs(..., olTxt)
does not have this problem:
set Session = CreateObject("Redemption.RDOSession")
set msg = Session.GetRDOObjectFromOutlookObject(myItem)
msg.SaveAs "c:\temp\test.txt", olTxt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |