0

After selecting the email item in Outlook, press ctrl+C and open a folder in Windows Explorer and press ctrl+V act save the email msg file to this folder.

At this time, the saved file name is designated as the subject of the email.

I succeeded in changing the title and saving it, but this method is cumbersome because it saves to a specific folder.

I'm trying to make a similar user experience with ctrl+C/ctrl+V.

How do I copy the email object item to the clipboard in the form of a file?

I tried MSForms.

Public Sub SaveMessageAsMsg()
    Dim oMail As Outlook.MailItem
    Dim objItem As Object
    Dim sPath As String
    Dim dtDate As Date
    Dim sName As String
    Dim enviro As String
    Dim sSender As String
    'Dim buf As MSForms.DataObject

    enviro = CStr(Environ("USERPROFILE"))
    For Each objItem In ActiveExplorer.Selection
        If objItem.MessageClass = "IPM.Note" Then
            Set oMail = objItem
            sName = oMail.Subject
            ReplaceCharsForFileName sName, "_"
            sSender = oMail.Sender
            If InStr(sSender, "/") > 0 Then sSender = Left(sSender, InStr(sSender, "/") - 1)
            If InStr(sSender, "(") > 0 Then sSender = Left(sSender, InStr(sSender, "(") - 1)
            dtDate = oMail.ReceivedTime
            sName = Format(dtDate, "yymmdd", vbUseSystemDayOfWeek, _
            vbUseSystem) & Format(dtDate, "_hhnn", _
            vbUseSystemDayOfWeek, vbUseSystem) & "_" & sSender & "_" & sName & ".msg"
            sPath = enviro & "\Documents\SaveMails\"
            Debug.Print sPath & sName
            oMail.SaveAs sPath & sName, olMSG
        End If
    Next
End Sub
Community
  • 1
  • 1
  • i have foggot ReplaceCharsForFilename function code. it works only change un-usable character to filename like '?', '/', \', etc. – Romanticcat Dec 01 '22 at 02:39
  • Does this answer your question? [Macro to save selected emails of Outlook in Windows folder](https://stackoverflow.com/questions/28479157/macro-to-save-selected-emails-of-outlook-in-windows-folder) – niton Jan 06 '23 at 16:05

0 Answers0