+ Reply to Thread
Results 1 to 12 of 12

Automate Outlook Emails with Attachments in Excel

  1. #1
    Registered User
    Join Date
    04-06-2021
    Location
    Accokeek, MD
    MS-Off Ver
    365
    Posts
    30

    Automate Outlook Emails with Attachments in Excel

    For each Project No on the attached, I would like to send the Company an automated Outlook email with their outstanding Document Number(s) as an attachment. If a Document No has multiple email addresses, I would like to send 1 email joining the email addresses with a semi-colon and 1 sum total for each Document No.

    Using data in the attachment --
    Project 1473, 1 email w/ 2 email addresses separated by a semi-colon, 1 line attachment
    Project 1782, 1 email w/ 2 email addresses separated by a semi-colon, 1 line attachment
    Project 1506, 1 email w/ 1 email address, 1 line attachment
    Project 1833, 1 email w/ 1 email address, 1 line attachment
    Project 1752, 1 email w/ 1 email address, 1 line attachment
    Project 1755, 1 email w/ 1 email address, 2 line attachment
    Project 1774, 1 email w/ 1 email address, 1 line attachment

    Following is the text for the email:

    To: email address
    From: G. C.
    Subject: Project No., Company, Due Date

    Attached are the outstanding invoices for your Company. Please contact G. C. if you have questions or need further explanation.
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Automate Outlook Emails with Attachments in Excel

    I took some liberties with this. I converted the raw data to an Excel Table. There are too many advantages to Excel tables not to use them. So I suggest you read up on them. I had to change the data to get the condition that 1755 should have only one email address. The way you had the data, it would have had two.

    I made two pivot tables to help me with formatting the data. The one in column A is a unique list of projects. The other one gets the company name, documents and email addresses for a project. I overlay the results of the pivot tables with named dynamic ranges.

    I use an outer loop for the project list, and two inner loops for the documents and the email lists.

    I feed the results to my "standard" mail program. I suggest you save this module since it can be used with other VB code. All you have to do is pass the parameters to it.

    With a little more work I can make a better Subject line (maybe including the project) and body (ditto) - the body I have is simply the documents, one per line. If you really want to make another spreadsheet and copy these values in and attach the spreadsheet, I can do that too.

    I tested the mailer with the FALSE flag.
    Please Login or Register  to view this content.
    With the false flag, the mailer will create the emails and put them on the desktop, but you will have to click the send button to send them. This gives you the chance to edit the email before sending it. Change the last argument from False to True and the mail goes out without human intervention.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    04-06-2021
    Location
    Accokeek, MD
    MS-Off Ver
    365
    Posts
    30

    Re: Automate Outlook Emails with Attachments in Excel

    Thank you so much for responding dflak.

    I tried to add the balance column after the Document No in your pivot table but that threw off the data for the email address. My programming experiece is very limited so I could not fix the macro.

    The actual lists are very lengthy, and the clients do calculations and sorting on the data. Consequently, I would like to create an excel spreadsheet with the data as an attachment to the email.

    Following is a sample of the cc, subject, email body, and signature block:

    -----------------------------------------------------------------------------------------------------
    CC:[email protected] (on all emails)

    Subject: Fisher Clinical Services (our name on all emails), Company (customer name), Customer No#,Customer Project Number

    Email Body: Attached are the outstanding invoices for your company. Your prompt payment is appreciated. If you have questions or need further information, please contact: (on all emails)

    Signature Block (on all emails)
    Garland Christmas
    Senior Credit Analyst, Fisher BioServices
    Pharma Services | Fisher Clinical Services, by Thermo Fisher Scientific
    14665 Rothgeb Drive | Rockville, MD 20850
    [email protected] | www.fisherbioservices.com

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Automate Outlook Emails with Attachments in Excel

    I've made a few adjustments to make it easier for you to manage the mail.

    The email addresses were done using a named dynamic range. I adjusted that so it now points to the correct column again. Also I added the company ID to the pivot table. If you don't want to see this, hide the column.

    I've included a Control Panel.

    You can basically "fill in the blanks". The Subject Line is calculated based on what gets returned in the pivot table. The Flag is sent to false, so the mail gets stacked on the desktop. Flip it to true and the mail will go out automatically.

    Press the Send Mail button and the mail will go out.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-06-2021
    Location
    Accokeek, MD
    MS-Off Ver
    365
    Posts
    30

    Re: Automate Outlook Emails with Attachments in Excel

    Thank you again dflak. The control panel makes it real easy to edit the email but there is no attachment. Am I correct in assuming that filtering and attaching the data is a manual process? If would be great if that could be automated too. If it is easier to have the data in the body of the mail, that will work too. The data consists of the Document No(s), Balance Due, and a SumTotal for the Project No.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Automate Outlook Emails with Attachments in Excel

    Let me restate what I thought you just said as I think I missed something in the requirement.

    You want an attachment (What format? Excel or PDF would be easiest) and it would contain the information that is shown in the pivot table. I will give the file a name based on the company ID and date unless you have a better idea. Finally, do you want to keep an archived copy of the attachment or do you want to dispose of it after posting. I can also put another item on the control panel: the directory in which you want to save the attachments if you choose to archive them.

    My mail code is already set up to mail attachments, so it is merely a matter of creating it.

  7. #7
    Registered User
    Join Date
    04-06-2021
    Location
    Accokeek, MD
    MS-Off Ver
    365
    Posts
    30

    Re: Automate Outlook Emails with Attachments in Excel

    Your clarification is accurate. An Excel attachment as well as the same text in the body of the email (before the signature block) would be perfect. I do not need an archival copy. Thank you sooo much!

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Automate Outlook Emails with Attachments in Excel

    Here you go.

    I added an attachment path. You will have to set this up manually the first time.

    The Attachment file is computed automatically

    There is also a Keep Attachment flag. True - the attachments will be kept. False - the attachments will be deleted after the mail is sent.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-06-2021
    Location
    Accokeek, MD
    MS-Off Ver
    365
    Posts
    30

    Re: Automate Outlook Emails with Attachments in Excel

    The Make Attachment macro puts the attachment in a folder I created but now I get a debug message when I try to run the DoMail macro. Also, will I have to create each attachment 1 by 1 before running the Mail macro? Some files will have the same file name so they will overwrite the previous one. Is this supposed to happen? I appreciate your patience with me this will be so helpful.

    The debug error message is at -- Set OutApp = CreateObject("Outlook.Application")

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Automate Outlook Emails with Attachments in Excel

    Do you have outlook installed?

    It should not have to be running.

  11. #11
    Registered User
    Join Date
    04-06-2021
    Location
    Accokeek, MD
    MS-Off Ver
    365
    Posts
    30

    Re: Automate Outlook Emails with Attachments in Excel

    It works, thank you so much. I had to reboot my computer for some updates to run.
    Last edited by clorodet20607; 05-30-2022 at 12:05 PM.

  12. #12
    Registered User
    Join Date
    04-06-2021
    Location
    Accokeek, MD
    MS-Off Ver
    365
    Posts
    30

    Re: Automate Outlook Emails with Attachments in Excel

    Hello again dFlak, I previously marked the post solved, but didn't realize the pivot table data is not in the body of the email. Is it possible to have the data in both places (the body of the email AND as an email attachment?
    Last edited by clorodet20607; 05-31-2022 at 01:19 AM. Reason: Outstanding Question

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Outlook emails pulling attachments from Sharepoint
    By Seth_ in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-01-2019, 07:33 AM
  2. [SOLVED] Macro in Excel to send emails in outlook sending hyperlinks but need attachments
    By L_Misty in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2017, 02:19 PM
  3. [SOLVED] Excel Macro to Send Multiple Emails w/ Attachments using MS Outlook 2007
    By arnel_10 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-17-2017, 08:09 PM
  4. Accessing Outlook Attachments from Saved Emails
    By crunchKH in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2013, 12:38 AM
  5. Macro to get the data exported to an excel from Outlook emails and or attachments?
    By lifeisaspreadsheet in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2012, 04:31 PM
  6. Excel to open workbook attachments in emails in Outlook subfolders
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2010, 09:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1