Auto Add a PDF to an outgoing Email, based on a rule

Status
Not open for further replies.

CJD

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hello

I would like to have a few PDF files and based on a keyword in the body of an outgoing Outlook message for the appropriate PDF to be autoattached

eg I might have
Audi.pdf
BMW.pdf
Toyota.pdf

in the outgoing email I would have a 'code string' for instance eg *audinews*

When this is seen Audi.PDF is auto attached


I would only ever have a case where one unique string would attach per email.

If there was a magic wa y to remove the string *audinews* from the emal body that would be ideal but not essential.


I have a few other requirements such as the Subject line changing based on the string - but the PDF auto attach is the key requirement

Could anyone recommended either
1) A Paid for tool - as I would like this to be simple for staff to manage
2) If its Macro based, any pointers to snippets of code would be greatly appreciated

Kind Regards
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It sounds like more fun that real work. :) This is one way of doing it -

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strCar As String, strFile As String, strKey As String
Select Case True
    Case InStr(LCase(Item.Body), "audinews")
        strCar = "Audi"
        strKey = "audinews"
        strFile = "C:\Users\drcp\Documents\Insert Text\file1.txt"
    Case InStr(LCase(Item.Body), "bmwnews")
        strCar = "BMW"
       strFile = "C:\Users\drcp\Documents\Insert Text\file2.txt"
        strKey = "bmwnews"
    Case InStr(LCase(Item.Body), "fordnews")
        strCar = "ford"
        strFile = "C:\Users\drcp\Documents\Insert Text\file2.txt"
        strKey = "fordnews"
End Select

With Item
    .Body = replace(.Body, strKey, strCar)
    .Subject = strCar & ": " & Item.Subject
    .Attachments.Add strFile
    .Save
End With

End Sub
 
Last edited:
Status
Not open for further replies.
Top