export report pdf to specific folder with variable file name (1 Viewer)

sadiq92

New member
Local time
Today, 23:45
Joined
Jun 4, 2020
Messages
29
That would require VBA Outlook automation code. Report PDF must first be saved to folder (which you already do) then attach to email Attachment property. Very common topic.
Can you give me the code?
 

June7

AWF VIP
Local time
Today, 12:45
Joined
Mar 9, 2014
Messages
5,463
There are many discussions with examples. Try searching Google or forum. Something like:
Code:
Private Sub Email()
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim body As String, rs As Recordset
Set appOutLook = CreateObject("Outlook.Application")
Set rs = CurrentDb.OpenRecordset("SELECT UmpID, Email FROM Umpires WHERE ID < 4")
Do While Not rs.EOF
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
        .BodyFormat = olFormatHTML
        .To = rs!Email
        ''.cc = ""
        ''.bcc = ""
        ''.Attachments.Add "filepath\filename"
        .Subject = "Test : " & rs!UmpID
        body = "<table style='text-align:right;border:1px solid black;font-family:calibri;border-collapse:collapse;padding:15px'><tr style='background:yellow;mso-highlight:yellow'>" & _
            "<th>No</th><th>Client</th><th>Date</th><th>PR</th><th>Currency</th><th>Amt</th></tr>" & _
            "<tr><td>12345</td><td>Jones</td><td>12Dec2017</td><td>ABC</td><td>US</td><td>2000</td></tr>" & _
            "<tr><td>67890</td><td>Finkbiner</td><td>12Dec2017</td><td>ABC</td><td>US</td><td>1000</td></tr></table>"
        body = "<HTML style='font-family:calibri'><Body><font face='calibri'><a href='" & HyperlinkPart("ABC#C:\Users\Owner\June\Forums#DEF", acAddress) & "'><img SRC=C:\Users\Owner\June\DOT\Lab\Editing\LABDB.png></a><br>" & _
            "<font color='red' size='1'>&nbsp;&nbsp;&nbsp;&nbsp;READ THIS EMAIL COMPLETELY</font><br>" & _
            body & _
            "<br><b>Please confirm or I will kick you.</b><br>" & _
            "</font></Body></HTML>"
            .Display
        'following allows including Outlook email signature
        .HTMLBody = Replace(.HTMLBody, "<div class=WordSection1><p class=MsoNormal><o:p>", "<div class=WordSection1><p class=MsoNormal><o:p>" & body)
    '    .Send
    End With
    rs.MoveNext
Loop
 

Users who are viewing this thread

Top Bottom