+ Reply to Thread
Results 1 to 16 of 16

Macro to create a draft email from Excel

  1. #1
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Exclamation Macro to create a draft email from Excel

    Hi all, so I want to create a macro that could draft an email, but not immediately sending it because I want to do a one last checking before sending.

    So I created 3 sheets in the file I've attached:

    1. Setup -> This is to setup the date and month that's written in the email, it's editable. Basically the Setup sheet is to cross-check if the day the email sent is not on either Saturday/Sunday. I've created a little button to check, so there's no issue there.
    2. Heading -> This is to insert Subject and put the list of To and Cc the people to send the emails to
    3. Email Content -> The content I want on the emails that I'd send

    I'm confused to create a macro that could:
    1. Input the Subject, To and Cc
    2. Everything written in Sheet "Email Content" is what I want in the email. The contents in that sheet is changeable. In the sample email I have a 8-row table, but it can also be a 2-row table and others
    3. Not immediately sending, just draft first so I can check if the contents are already good to go

    Can anyone help me on this? I've attached the sample file that I've created with all the sheets.

    Oh yeah, as a note, I use Ms. Outlook.

    Thank you so much in advance!
    Attached Files Attached Files
    Last edited by nettadecoco; 12-06-2022 at 12:04 PM.

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

    Re: Macro to create a draft email from Excel

    I could not discern where you are getting the various pieces for the mail from, especially the mail addressees. However, you seem to be somewhat familiar with VBA. I am sending your workbook back to you with my mailer module included. What you need to do is write VB code to pass whatever you want to it.

    Here is the list of parameters you can pass to it:

    ' ToString = List of addressees in To field, semicolon delimited
    ' SubjectString = Subject of the mail Message
    ' BodyString = Body of the mail message
    ' ReplyTo = (Optional) Reply to email address
    ' OnBehalfOf = (Optional) Mail on behalf of (must have permissions)
    ' CCString = (Optional) List of addressees in CC field, semicolon delimited
    ' BCCString = (Optional) List of addresses in BCC filed, semicolon delimited
    ' AttachmentName = (Optional) List of full-path name attachments, semicolon delimited
    ' HTMLRange = (Optional) Range to include as HTML
    ' SendDisplay = True = Send mail automatically, False = display only as draft

    You may only need the first three and the last. By default, the SendDisplay flag is set to false. This means, prepare the mail as a draft, but don't send it.

    Also, you might have to send your table in the body as an HTML range.
    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
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Macro to create a draft email from Excel

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Macro to create a draft email from Excel

    Hi dflak and JEC, thanks for your replies!

    dflak, I somewhat familiar with the If formula because I've used it for work too many times but still not getting the hang of the rest actually hahaha... So, for the sheets I've created, I want the macro to refer to those cells:

    1. For the Sheet Heading -> the Subject in Outlook should refer to C1 and the emails sent To should refer to the list of email addresses in Row B4 onwards, while Cc should refer to Row C4 onwards
    2. For the Sheet Email Content -> it's the body of the email... is it possible to make the body of the email to refer to all cells that is not blank, including the table in the form of the table, not attachment?

    And I want the send command to be inside a button that I could click. I've attached the sample file with the button and table of To and Cc to make it clearer.

    I'll be grateful for your reply! Thank you!
    Attached Files Attached Files
    Last edited by nettadecoco; 12-07-2022 at 01:55 AM.

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

    Re: Macro to create a draft email from Excel

    I took a couple of liberties in case you want to use this utility for other than sending out invoices.

    The first thing I did was to put the information about the email in an Excel table. There are too many good reasons to use Excel Tables not to use them. One of them is that tables know how big they are, so as you add information to the table, charts, formulas and pivot tables adjust to accommodate the new data. Also, if you look at the VB code, you'll see how easy it is to refer to table parts by name making the code easier to write and to maintain.

    I added two additional columns: Company and Salutation to make the mails a bit more personal. I can back this out.

    On the Setup Page, I added a Mail_Prefix. You could change this to "Holiday Greetings for " or whatever other customization you would like.

    Also in the email content sheet, I fill in the name of the contact in cell B3.

    The body is a "fixed" range B3:H18. You may want to change this too if you are sending something other than an invoice. The named range to apply to what you want to send is Mail_Body. Use Formulas > Name Manager to change it.

    Other than that, the code runs down the list of companies and gets the appropriate pieces to pass to the main mail program.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Macro to create a draft email from Excel

    Hi dflak, thank you for your reply!

    It works wonderfully and I can't thank you enough!

    Just this, how do I make it so that it's only sending 1 email, but to many people? So let's say there's 3 people in To, and like 10 people in Cc but it's sending only 1 email?

    Thank you!

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

    Re: Macro to create a draft email from Excel

    Separate each To and CC with a semi-colon just like if you were sending mail manually.

  8. #8
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Macro to create a draft email from Excel

    Okay, thank you very much dflak!

  9. #9
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Macro to create a draft email from Excel

    Hi, dflak, sorry to bother you again. So, I have a signature in my Outlook, but it doesn't show here when I generate the email with macro. How do I add my signature in the macro so that the generated email would be able to have signature in the bottom?

    Thank you!
    Last edited by nettadecoco; 12-08-2022 at 03:17 AM.

  10. #10
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Macro to create a draft email from Excel

    Hi dflak, sorry for updating this thread again.

    What if I want to send two different emails with different To and Cc and different Mail Body? In the current macro, the Mail Body is only 1 and can be sent to many recipients, but what if I want to send 2 different emails entirely? So, for example... there will be "Email Content 1" and "Email Content 2" sheets. The "Email Content 1" is for the first row, and "Email Content 2" is for the second row for the "Heading" sheet.

    Sorry for bothering you, thank you!
    Last edited by nettadecoco; 01-11-2023 at 04:39 AM.

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

    Re: Macro to create a draft email from Excel

    Off the top of my head ... make a copy of the spreadsheet and then create a second body on the second spreadsheet.

    I need to look at the utility I sent you. At the core is a macro that takes a number of parameters. One of those parameters is the mail body. I have to see the code I wrapped around it calls this routine. Also, you might have some kind of a formula for the mail body that switches based on to whom the mail is sent. Once I look at the utility, I can make a better suggestion.

    My apologies for being late on the replies. I've been on a whirlwind of interviews lately.

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

    Re: Macro to create a draft email from Excel

    The email body is determined by a fixed named range: 'Email Content'!B3:H18.

    Anything within this range of cells becomes the body of the email.

    Things may work better if instead of being a name for a fixed range, the range is a named dynamic range. Generally speaking, this will change the number of rows and columns contained in the body. However, I'd need to know what possible bodies would look like.

  13. #13
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Macro to create a draft email from Excel

    Hi, dflak! Thank you so much for taking your time to reply this! I hope your interviews went well

    Actually, the body is more or less the same, just the amount that's different. I've attached it here.

    Thank you so much for your help!
    Attached Files Attached Files

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

    Re: Macro to create a draft email from Excel

    What I need now is a way to determine which content to use. It appears that the content is dependent on who the mail goes to. I think I can come up with a way that you can have a sheet for every person in the table. You will define the sheet name and range for each person. I'll have to do some minor recoding to do this.

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

    Re: Macro to create a draft email from Excel

    Here is a version that should work. The code tweak was easier than I expected.

    There are two new columns in the table that defines who the mail goes to. One defines which sheet the body is found on, the other defines what cell range on that sheet you want to use. Of course, the same sheet / range combination can be used for multiple people. You do not need a unique combination for every record.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Macro to create a draft email from Excel

    Hi, dflak! Thank you so much for your help! The code works wonders!

    I hope you have a good day!

+ 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. Create MS Outlook Email from Excel and Save to Draft Folder
    By jski21 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2020, 05:55 AM
  2. Draft email create from vba, body to contain worksheet
    By rbeech23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2020, 11:54 AM
  3. [SOLVED] A macro to copy a worksheet to a new workbook and create an email draft with the new ws
    By skylinekiller in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-05-2018, 07:25 PM
  4. Macro to automatically draft email and save in a Folder
    By Mr.India in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2015, 12:16 PM
  5. Copy data from excel to Outlook new email and create draft.
    By G.Bregvadze in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2013, 03:31 AM
  6. Create Outlook Draft along with attachment via Excel Macro
    By sekar.suman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 07:37 AM
  7. Create Lotus Notes Draft email from filtered or unfiltered List
    By Jimmy0306 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-07-2009, 09:03 PM

Tags for this Thread

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