Solved

Email Templates / Quick Attachments

Posted on 2014-01-28
12
351 Views
Last Modified: 2014-02-12
Hello Experts,

I often reply/start new emails to customers, which I need to send specific attachments.

Right now, all of the attachments (files) are located on a corporate network folder in which I drag the files into the email to attach.  Yes, doing so is very easy as it is - but is there an even easier way of doing so?

Ideally, I would love to have a series of buttons - (Example: 'Custom Capabilities', 'Credit Application') along the top of the email (I think it's called the ribbon?) - where I just click the button and it automatically adds the attachment, without me having to navigate or select it myself.

Is this even possible?

Thank you in advance for your help!
~ Geekamo
0
Comment
Question by:Geekamo
  • 7
  • 5
12 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39818098
Hi, Geekamo.

Yes, that's possible if you have outlook 2010 or later.  To do this you need a few simple macros to handle adding the attachments.  You can then add the buttons to the ribbon yourself and connect each button to the correct macro.  Each macro would be something like this.

Sub AddCustomCapabilitiesAttachments()
    Dim olkMsg As Outlook.MailItem
    Set olkMsg = Application.ActiveInspector.CurrentItem
    'Add a line like the following for each file you want to attach
    olkMsg.Attachments.Add "\\server\share\file1.doc"
    olkMsg.Attachments.Add "\\server\share\file2.doc"
    Set olkMsg = Nothing
End Sub

Open in new window


All you need to do is duplicate this macro, change it's name, and add/change the names of the files you want to attach.  

If you have Outlook 2007, then something similar is possible, only instead of adding buttons to the ribbon you'll add them to the quick action toolbar.
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39818586
@ BlueDevilFan,

I haven't tested this yet, but is it possible to return an error message if,...

1.) The folder location is not available.
2.) The file itself is not there.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39818794
Yes, that's possible.  Something like this

Sub AddCustomCapabilitiesAttachments()
    'On the next line enter the list of files (to include path) of the files you want to attach.
    'Each file must be separated from the previous filename by a comma.
    'Do not put a space after the comma.
    Const FILES_TO_ATTACH = "\\server\share\file1.doc,\\server\share\file2.doc"
    Const MACRO_NAME = "Fast Attach"
    Dim olkMsg As Outlook.MailItem, objFSO As Object, arrFiles As Variant, varFile As Variant, strFolder As String, strFile As String
    Select Case TypeName(Application.ActiveWindow)
        Case "Inspector"
            Set olkMsg = Application.ActiveInspector.CurrentItem
            arrFiles = Split(FILES_TO_ATTACH, ",")
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            For Each varFile In arrFiles
                strFolder = objFSO.GetParentFolderName(varFile)
                strFile = objFSO.GetFileName(varFile)
                If objFSO.FolderExists(strFolder) Then
                    If objFSO.FileExists(varFile) Then
                        olkMsg.Attachments.Add varFile
                    Else
                        MsgBox "I could not find a file named '" & strFile & "' in the folder '" & strFolder & "'.", vbCritical + vbOKOnly, MACRO_NAME
                    End If
                Else
                    MsgBox "I could not find a folder named '" & strFolder & "'.", vbCritical + vbOKOnly, MACRO_NAME
                End If
            Next
        Case Else
            MsgBox "You must have a message open before you can attach anything to it.", vbCritical + vbOKOnly, MACRO_NAME
    End Select
    Set olkMsg = Nothing
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Geekamo
ID: 39825806
@ BlueDevilFan,

Thank you for your replies.  I finally have free time (yay, the work week is over!)  Now I can finally test this out.  I will keep you posted.

~ Geekamo
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39825812
@ BlueDevilFan,

I have added the code,...

Sub AddCustomCapabilitiesAttachments()
    Dim olkMsg As Outlook.MailItem
    Set olkMsg = Application.ActiveInspector.CurrentItem
    'Add a line like the following for each file you want to attach
    olkMsg.Attachments.Add "C:\Users\jburke\Desktop\Files\yourfile.png"
    olkMsg.Attachments.Add "\\server\share\file2.doc"
    Set olkMsg = Nothing
End Sub

Open in new window


And added a button to my New Email messages, and when I click on the button to execute the macro - nothing happens.

Any ideas?

~ Geekamo
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39825873
@ BlueDevilFan,

I don't know if this will help you in troubleshooting the code not working for me, but I did a Google search and found code for this.  The only problem, it doesn't do "exactly" what I want it to do.  But it "does" work.

Sub AddAttachment()
 Dim myItem As Outlook.MailItem
 Dim myAttachments As Outlook.Attachments
 
 Set myItem = Application.CreateItem(olMailItem)
 Set myAttachments = myItem.Attachments
 myAttachments.Add "C:\Users\jburke\Desktop\Files\yourfile.png", _
 olByValue, 1, "Test"
 myItem.Display
End Sub

Open in new window


The code above, does add the file - without any problem.  But,..  it only does this by creating a new email message.  I would like this code to work on an email that is already open.  So basically, I plan to only execute the code from the ribbon menu on a new email item.

Also, the code above doesn't account for multiple files I may attach.

Thank you in advance for your help!

~ Geekamo
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 76

Expert Comment

by:David Lee
ID: 39826448
Geekamo,

I just re-tested the solution and it worked perfectly.  The code you found on Google doesn't help.  It's doing exactly the same thing that my code does, it's just doing it in a slightly different way.  

What happens when you run my solution?  Are you sure the code is running?  What message format (e.g. HTML, Rich Text) are you using for your messages?
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39831684
Hmm, I'm not technically sure if your code ran.  But I wasn't doing anything different then I was in the code that did work.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39832043
How about my other question?  What message format are you using for your messages?
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39832336
its rich text or html.  not sure what its called, but its not the plain text i know that.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39835191
Rich Text and HTML handle attachments in different ways.  Please check to see which format it is.  You can do that by creating a message and looking at the top of the window the new message is in.
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39837669
It's html
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now