Link to home
Start Free TrialLog in
Avatar of Geekamo
GeekamoFlag for United States of America

asked on

Email Templates / Quick Attachments

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
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Geekamo

ASKER

@ 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.
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

Avatar of Geekamo

ASKER

@ 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
Avatar of Geekamo

ASKER

@ 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
Avatar of Geekamo

ASKER

@ 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
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?
Avatar of Geekamo

ASKER

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.
How about my other question?  What message format are you using for your messages?
Avatar of Geekamo

ASKER

its rich text or html.  not sure what its called, but its not the plain text i know that.
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.
Avatar of Geekamo

ASKER

It's html