Tech Language logo

by Steven Marzuola


Converting email messages to Microsoft Word format.

A client needed translations of about 150 email messages that had been stored in Outlook .msg format. If it was just a few of them, the simplest approach would be to open each one individually, copy the content to another format such as Microsoft Word, and translate the result.

But with 150 messages, the process would be time-consuming and error-prone.

As an alternative, each message could be "Saved As" an HTML file. Still clumsy and probably not as convenient to handle.

The approach taken was to write a macro in VBA (Visual Basic for Applications) to perform this conversion in bulk. The user selects the desired message(s) and runs the macro. The macro opens each message and exports it to the Microsoft .doc (not .docx) format. This is fast, occurring in seconds.

The obvious choice for the filename of each converted messages is the subject line. However:

If the messages are stored as .msg files, first first create a message folder in Outlook. Then drag the messages from a File Explorer window to the Outlook.

Possible improvements

VBA code

Sub SaveAsDoc()

' By Steven Marzuola - January 2021 - www.techlanguage.com

Dim i as Long
Dim objSelection As Outlook.Selection
Dim myPath As String
Dim SerialNo As String
Dim newFilename As String

myPath = "C:\DOC output files\"

Set objSelection = Outlook.Application.ActiveExplorer.Selection

If Not (objSelection Is Nothing) Then
For i = 1 To objSelection.Count
If objSelection(i).Class = olMail Then
SerialNo = Trim(Str(i)) & " "
newFilename = CleanFilename(SerialNo & objSelection(i).Subject & ".doc")
objSelection(i).SaveAs myPath & newFilename, olDoc
End If
Next
End If

End Sub


Function CleanFilename(S) As String

Dim J as Long, S2 as String
Const mySpecials = ">:/\|?*,!@#$%&^" & """"

S2 = S

For J = 1 To Len(mySpecials)
S2 = Replace(S2, Mid(mySpecials, J, 1), "")
Next J

S2 = Replace(S2, "", "")
S2 = Replace(S2, "", "")

CleanFilename = S2

End Function


January 26, 2021
Back to Steven Marzuola's Tips
Home:www.techlanguage.com