+ Reply to Thread
Results 1 to 11 of 11

Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

  1. #1
    Registered User
    Join Date
    04-13-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 365
    Posts
    6

    Question Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    Hello,

    I'm pretty new to macros and VBA and would be super grateful for some help with a pet project I've been working on over the past few weeks.

    My project is a form where in the first worksheet the user selects various inputs from pre-defined (data validation) lists, which draws corresponding information from other "database" sheets (tables) and compiles it in an "output" sheet, which is basically the entire body of an e-mail, ready to copy and send. The recipient and CC addresses are stored in specific cells in a hidden sheet, and may change depending on the user's input in the first sheet. The from and BCC addresses should also be pre-set, but to a specific e-mail address which will not change depending on user input.

    I'm at the point now where the entire form works as intended and generates the necessary output, ready to transfer to Outlook. I've created the command button, but I need help with the attached macro/VBA coding. I've found some simple tutorials for how to generate an e-mail from Outlook, but they all seem to include a fixed recipient, subject, body text etc., and I need those to be dynamic.

    Here's the process I need automated:
    1. Select cells B3 to B461 in the output sheet (this range will always be the same; empty rows are automatically hidden)
    2. Copy the selection
    3. Open Outlook and create a new e-mail
    4. Set "From" (if possible) and "BCC" to a fixed e-mail address
    5. Retrieve the recipient e-mail address from a specific cell in a hidden sheet
    6. Retrieve the CC e-mail addresses from a specific cell in the hidden sheet (they are already stringed together in Outlook format, separated by semicolons)
    7. Retrieve the e-mail subject from a specific cell in the hidden sheet
    8. Paste the selection into the e-mail body
    9. If possible, once pasted, convert the pasted selection from table to text using paragraph marks to separate text

    I suppose this should be possible to do, and maybe it's not even that complicated, but it's currently too advanced for me to figure out on my own.

    Any help would be greatly appreciated!

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    See top yellow banner
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    04-13-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 365
    Posts
    6

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    Thanks, I've created a sample workbook showing as simply as possible what I'm trying to do.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    There is so much to find on this topic that I don't expect you to be helped much further by first putting some time into it yourself.

    To start somewhere, study the link https://docs.microsoft.com/en-us/pre...ectedfrom=MSDN

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    See these links below...Between the two you should be able to get some guidance...If you don't come right I'll have a look in the morrow...
    https://www.excelforum.com/excel-pro...ml#post5311589
    https://www.excelforum.com/excel-pro...ml#post5311580

  6. #6
    Registered User
    Join Date
    04-13-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 365
    Posts
    6

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    Hello again! Sorry for the late bump; I've been back in the office for the past few weeks and haven't had the time or energy to work on this project.

    Today I've been working with the various resources that you shared, and I now have my file running almost exactly how I want it to - thanks a lot to both of you!

    All that remains to fix are two small issues of formating:
    1. The cell range that is copied and pasted into the e-mail body is pasted as a table, and I'd like it to be converted to text automatically. Outlook has a "Convert table to text" option, but I'd like to run that directly through the VBA code, if possible.
    2. Superfluous spaces are added before and after the pasted content in the new e-mail. Is there a way to remove those automatically?

    Updated sample workbook attached.
    Attached Files Attached Files
    Last edited by kjaer88; 05-05-2020 at 06:46 AM.

  7. #7
    Registered User
    Join Date
    04-13-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 365
    Posts
    6

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    I'm still trying to figure out those last two issues if anyone can help (most importantly the automatic conversion from Excel table to text in Outlook).

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    Play around with this...
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-13-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 365
    Posts
    6

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    Not only did you shorten the entire code, it also solves both of my problems. Brilliant; thank you so much!

    It's almost perfect now. I'm down to fine-tuning the font size, which is proving to be more difficult than I would have imagined, given that I do have prior knowledge of HTML and CSS.

    If I don't address it at all, the text is pasted into the new e-mail as size 10px, even though the default in a new e-mail is 11px (which is what I want).

    I've tried different variations of HTML and CSS manipulations, but it appears that the "px" unit or any decimals in the font size are completely ignored.

    Thus the closest I've come so far is applying a span tag with inline styling, setting the font size to "15", which returns 11,5px in Outlook. If I set it to "14" it returns 10,5px. If I set it to "14.5" or "14,5", it goes back down to just 10px, i.e. decimals don't seem to work.

    At this point I'm only half a font size away from having exactly the solution I imagined, so I suppose I could live with that, but it seems like there should be an easy fix for this too.

    Either way, I really appreciate your help with everything so far!
    Attached Files Attached Files

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    Have added code in attached...Play with Font Name & Font Size
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    04-13-2020
    Location
    Norway
    MS-Off Ver
    Microsoft Office 365
    Posts
    6

    Re: Create ready-to-send e-mail in Outlook based on dynamic cell values in Excel

    Much appreciated, however I'm still unable to set font size to exactly 11px in Outlook, just like with my own HTML and CSS attempts. I've tried different combinations of values and units, with and without decimals, and it does manipulate the font size, but the closest I can get to 11px in Outlook is 10,5px or 11,5px. It's a very odd problem.

+ 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] Send outlook mail based on a today's date and customer name
    By manieldunk in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 06-20-2018, 02:04 PM
  2. VBA auto outlook 2016 to send e-mail based off criteria
    By broman5000 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-30-2017, 04:15 PM
  3. [SOLVED] Code to send mail copying from Excel to a new outlook mail.
    By paz1987 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-11-2015, 07:54 AM
  4. Based on Birthdate in excel , Automatically send outlook mail with birthday wishes
    By ajaypal.sp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2015, 08:28 PM
  5. How to Send mail based on the values in a particular cell
    By sugaprasad in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-21-2014, 06:01 AM
  6. Filter based on today's date and send mail in outlook
    By kandanuru in forum Excel General
    Replies: 0
    Last Post: 06-15-2012, 04:59 AM
  7. Spreadsheet opens ready to send it outlook
    By Anthony in forum Excel General
    Replies: 1
    Last Post: 07-15-2005, 02:05 PM

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