+ Reply to Thread
Results 1 to 18 of 18

VBA Code to Email using addresses, subject, and body from cell contents

  1. #1
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    VBA Code to Email using addresses, subject, and body from cell contents

    Hello,

    I am seeking some assistance in creating VBA code for Excel (windows office 2016 and 365). I am starting to learn the language and have very limited experience. I have also tried adapting code currently available on the net, without success.

    I have two worksheets in my workbook named “Blastout” and “Personnel”.

    In the “Personnel” worksheet, I have the following columns:
    -column “C” which lists selected email addresses for a SELECTIVE BLASTOUT;
    -column “D” which lists ALL email addresses for an ALL BLASTOUT;

    The “Blastout” worksheet will essentially replicate an email window, where the user can input the email subject and email body. It will consist of:
    -Cell B3: Email Subject
    -Cell B5: Email Body
    -A form control button that activates a macro blastout_selected which will BCC send the email subject (B3) and body (B5) to every email address in column C of the “personnel” worksheet;
    -A form control button that activates a macro blastout_all which will BCC send the email subject (B3) and body (B5) to every email address in column D of the “personnel” worksheet;

    I greatly appreciate any assistance that fellow users can provide. Thank you!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Assign these macros to the appropriate buttons. They assume that the email addresses start in row 2 of the "Personnel" sheet.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Hi,
    Thank you immensely for your time and effort! One small hiccup. On attempting to run the above code, I am faced with a "Compile Error: For without Next." Do you have any suggestions or edits? Thank you in advance. You are a life saver to date.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Oops. Insert this line of code
    Please Login or Register  to view this content.
    directly below this line
    Please Login or Register  to view this content.
    in both macros.

  5. #5
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Hi again,
    One step closer. The code runs and generates a new email in Outlook with the subject and body populated. However, the BCC field remains empty. Just to be certain that the BCC wasn't causing the issue, I amended the code so the "rng.Value" appeared next to the .To= field instead, but still no success. Of note, there are some blank fields in columns C and D where there are NO email addresses. Could this be causing the issue? Any final suggestions? Thanks again.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Try:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Hello again,

    I feel like we are getting there The updated code populated the email address from the "Personnel" worksheet, but only the TOP email address in EACH column. The additional email addresses below rows C2 and D2 failed to populate. I realize this is becoming a bit tricky, but continue to appreciate your help!

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    I tested the macro on a dummy file and it worked properly. It would be easier to help and test possible solutions if you could attach a copy of your file (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file.

  9. #9
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Hi, It would be too difficult to de-sensitize my sheet, but I also created a dummy file for troubleshooting. Unfortunately, it would still only import ONE email address from columns C&D. I will attempt to attach the dummy file so that you can hopefully see what I am doing wrong. Thanks again.
    Attached Files Attached Files

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    In the "Personnel" sheet, row 1 is blank and your emails start in row 3 not in row 2. Replace this line of code:
    Please Login or Register  to view this content.
    with this line:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    I'm really not sure what I'm missing. I've adjusted the code as you specified, but it continues to only import the BOTTOM email address in each column. I've attached a test sheet again. From what I can tell, the coding looks correct. Would the error have something to do with the lack of semi-colons ";" between the email addresses?
    Attached Files Attached Files

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Try:
    Please Login or Register  to view this content.

  13. #13
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Quote Originally Posted by misc9700 View Post
    I..... it continues to only import the BOTTOM email address in each column.
    If you change .display to .send it will have sent all the the emails using Mumps previous code, you only see the last of the looped items in the displayed email.

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    @davesexcel
    Thank you for your suggestion.
    The last version of the macro (Post #12) now displays all emails. In the original macro, I had misplaced this line of code:
    Please Login or Register  to view this content.
    outside the loop. It is now inside the loop so a new email is created and displayed for each variable (rng).

  15. #15
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Ah I see what you folks have done. Genius! And it works! Thank you.

    My only concern is that there will eventually be around 100 email addresses in each column. If I understand correctly, this will open and send 100 separate emails. Is there any way to have all of the email addresses (separated by a ";" in ONE email so as not to overwhelm Outlook and the mail server (and my sent items mailbox lol)?

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Try:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    01-02-2021
    Location
    Ottawa, ON
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    Amazing! Well it certainly hasn't been easy, but it works. I can't thank you enough for all of your assistance. I am slowly learning VB code, but this would have taken many months to figure out. Once again, thank you.

  18. #18
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA Code to Email using addresses, subject, and body from cell contents

    You are very welcome.

+ 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] How to add mail addresses, Subject and body from excel to outlook
    By zaska in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-20-2016, 04:08 PM
  2. [SOLVED] vba for button to send email with cell contents in subject and body
    By Angelique Cassam in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2016, 01:48 PM
  3. Use a cell value as part of email subject or Body
    By egrospe17 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2016, 12:19 PM
  4. Cell value in email subject and cell selection in email body
    By xatomicx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2013, 12:31 PM
  5. email with corresponding addresses and names in body AND subject using gmail
    By excel4phil in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-22-2013, 04:09 AM
  6. [SOLVED] Email Range of Cell Content to create subject and body from link
    By Hahndo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2005, 07:05 PM
  7. want to mail workbook to addresses in range, subject and body in cells
    By arunjoshi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2005, 12:01 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