Solved

Automatically Attach PDF file to all reply emails as well as newly created emails

Posted on 2016-10-27
10
38 Views
Last Modified: 2016-10-27
Is there a way to automatically attach a PDF file whenever someone replies to an email in outlook as well as attach this same PDF to a newly created email? I need to attach a PDF file to basically ALL outbound emails whether they are replies or new emails from scratch. Can this be done in Outlook VBA?
0
Comment
Question by:Lawrence Salvucci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41862150
You could try to use the ItemSend event

Public WithEvents myOlApp As Outlook.Application
Public Sub Initialize_handler()
 
 Set myOlApp = Outlook.Application
 
End Sub
 
 
 
Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

Set myAttachments = Item.Attachments
myAttachments.Add Source:="C:\My Documents\Disclaimer.pdf", Type:=olByValue, DisplayName:="Disclaimer"
 
End Sub

Open in new window

for reference
https://msdn.microsoft.com/en-us/library/office/ff865076.aspx

Regards
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41862172
I put the code in a new module and ran it but it didn't attach anything. Did I miss something? Here is what I put:

Public Sub Initialize_handler()
 
 Set myOlApp = Outlook.Application
 
End Sub
 
Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim myAttachments As Outlook.Attachments
Set myAttachments = Item.Attachments
myAttachments.Add Source:="D:\BC Terms and Conditions.pdf", Type:=olByValue, DisplayName:="Disclaimer"
End Sub

Open in new window

0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41862189
it misses the with event and you have to close and reopen OL
Public WithEvents myOlApp As Outlook.Application

Open in new window

The sample code must be placed in a class module, and the Initialize_handler routine must be called before the event procedure can be called by Outlook.
0
Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41862194
I added that line of code and then closed and opened OL and still nothing. Does the "Initialize_handler" routine stay in the class module with the rest of the code or does that go in a separate module?
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41862205
in the class module
 but outside the sub
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41862213
is the code in "ThisOutlookSession" module?
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41862218
No. I put it in a new class module. Should it be in the "ThisOutlookSession"?
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41862220
I think so
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41862233
I put it there and it's working now. I am putting the attachment on my network server so if a user goes to send an email from their laptop and they are not connected to the network then they will not be able to grab the attachment. Is there a way to just bypass the attachment if it cannot be found since they are not on the network instead of having it error out? This is only for users that send emails while on the network in the office. When they are outside the network they don't have to attach this file but I don't want the code to error out.
0
 
LVL 51

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 total points
ID: 41862264
you can test if a file is there with

Res = Dir("c:\myFolder\myFile.txt")
if Res <> "" then
'attach file
End if

Open in new window

0

Featured Post

Windows running painfully slow? Try these tips..

Stay away from Speed Up Computer Programs that do more harm than good.
Try these tips instead.
Step by step instructions in trouble shooting Windows Performance issues.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't know how to downgrade, my instructions below should be helpful.
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question