Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

vba - Save sent Outlook Email (w/attachments) from Excel

I am using an Excel file to send personalized emails from a shared Outlook inbox. The code for sending the email is working well, but I am missing how to save the sent email item (incl. it's attachments) to a local network location (let's call it "One Drive-User101").

Right now, I manually save each sent email as a PDF to the local folder and name it according to the recipient's personalized info (cell values).

This last bit of code would completely automate the task so I am desperate for the solution!

Here is the code I have now:

Sub send()
    
    Dim OutApp      As Object
    Dim OutMail     As Object
    Dim mailBody    As String
    Dim greet       As String
    Dim name        As String
    Dim x           As Integer
    Dim eRow        As Long
    
    eRow = Cells(Rows.Count, 15).End(xlUp).Row
    For x = 4 To eRow
        
        If Cells(x, 15) = "Ready" Then
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
            
            mailBody = ActiveSheet.TextBoxes("confirm").Text
            greet = Cells(x, 33).Value
            name = Cells(x, 29).Value
            
            mailBody = Replace(mailBody, "Employee_Greeting", greet)
            mailBody = Replace(mailBody, "Employee_Last_Name", name)
            
            With OutMail
                .SentOnBehalfOfName = "[email protected]"
                .To = Cells(x, 27).Value
                .CC = Cells(x, 26).Value & ";" & Cells(x, 23).Value
                .Subject = "Confirmation"
                .HTMLBody = mailBody
                '.Attachments.Add ("C:UsersOneDrive - User101Confirmation Letter.pdf")
                .Display
                '.Send
                '.SaveAs
                '.PrintOut
            End With
            Set OutMail = Nothing
            
            Cells(x,15) = "Prepared"
        End If
        
    Next x
    
    Set OutApp= Nothing
    
End Sub
question from:https://stackoverflow.com/questions/65909281/save-sent-outlook-email-w-attachments-from-excel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...