+ Reply to Thread
Results 1 to 9 of 9

Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

  1. #1
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    Hi Guys,

    I have been searching this forum and google for hours over 3 days to have this done, and yes, I have checked on Ronde Bruin's site and I cant figure it out. All I want is to include 5 dynamic tables that I have in excel as part of a body of an email in outlook, exactly as how they look like in excel. I have already figured out everything else like sending the email in "on behalf", sending it to multiple recipients, having the subject to be time specific, having a hyperlink as part of the body with signature, and I'm now stuck with just the tables that is the main purpose of the email.

    The file contains 5 sheets. 4 tables would come from "On today" sheet which is arranged vertically separated by an empty row after each table, and the remaining table would come from a different sheet labelled as "individual". All tables are 7 cells wide, and would grow indefinitely down the table.

    The table would look something like the sample below. The underlined word is a hyperlink which I already know how to do.

    Please check on the data below.
    Date 1 2 3 4 5 6
    1/1 a b c d e f
    1/2 g h i j k l
    1/3 m n o p q r

    Date 1 2 3 4 5 6
    2/1 a b c d e f
    2/2 g h i j k l
    2/3 m n o p q r

    Additionally, here's part of the code that I used. I am hoping that your solution would pick up from here since this is more understandable to me. Hoping that I have posted all the information needed. And thanks in advance

    Dim olApp As Outlook.Application
    Dim olEmail As Outlook.MailItem
    Set olApp = New Outlook.Application
    Set olEmail = olApp.CreateItem(olMailItem)
    With olEmail
    .SentOnBehalfOfName = "name"
    .BodyFormat = olFormatHTML
    .Display
    .HTMLBody = "Body" & .HTMLBody
    .To = "To"
    .Subject = "Subject"
    End With
    Last edited by richardking; 06-29-2016 at 01:32 AM.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    did you read this section from rons site?
    http://www.rondebruin.nl/win/s1/outlook/bmail2.htm

    doesnt look like it from the code you have thus far
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    Yes I did, and that's what I meant when I said I already checked out Ronde Bruins website, and that topic most especially. Apologies I wasn't clear enough on that one. I'm also using Excel 2013. The code I used is something that is most understandable to me, which also means that I can modify it by myself as I need to. But if you guys have a different approach that still uses HTML and can do what it's intend to do, then that's fine. The important thing is I am able to get this done with your help guys

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    you need to adjust is the range for RangeToHtml

    ie instead of using
    Please Login or Register  to view this content.
    set rng yourself

    if you dont know how to set your own rng, post a sample file of your data setup
    so i can have a look at how this can be achieved

    then the next part is figuring out how to loop it so all the tables get added

  5. #5
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    Hi, here is a sample file. Thank you so much for looking into it.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    took it basically all from Ron's code
    changed slightly to represent your data

    cant update the code directly due to the html references
    this forum doesnt like it

    and im not re-attaching a 1.8mb file

    so attached the code in text file

    this is the important piece of code
    Please Login or Register  to view this content.
    change to suit
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    Thank you so much for the code.

    I have realized two things. First, I wanna cry because it did what it's supposed to do, and not only that, it also did an "auto fit" function which was supposed to be my next concern. This really made my day. Thank you so much. My second realization is, there is so much for me to learn. I really don't understand the code that would put the range of cells in excel as part of the body of the outlook email. Everything in the code is something I can understand, thus I can also recreate, but the rest of the code, it made me nauseous. But nonetheless, thank so much.

    If only it's possible, I would send you a beer
    Last edited by richardking; 06-30-2016 at 05:40 PM.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    glad it it helped

    there is so much for me to learn
    this would go for pretty much most people here, myself included

    the majority of the code was Ron's so really credit to him for creating it and posting for the world to reference
    i wouldn't remember how to write it personally i knows what each section does based on the comments on the file
    so i just have the link handy for when i need it to copy

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  9. #9
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Re: Send Table/Range of Cells As Part of Body through Outlook(HTML) using VBA

    Just did, thanks

+ 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] Vba to draft html body in outlook
    By arun.sj in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-15-2015, 07:37 AM
  2. How to send a Spreadsheet in the body as a table in Outlook
    By starlev in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2015, 09:26 AM
  3. Using HTML Body Format in Outlook mail
    By akash kothari in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 11:33 AM
  4. Excel ws into outlook html body with current html signature
    By Cadelanne in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2014, 09:03 AM
  5. Send e-mail with image on body (.html) on e-mail manager <> outlook
    By mariotnc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2012, 09:28 PM
  6. Send mails attaching files with HTML body range of content
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-16-2011, 09:55 AM
  7. Excel macro to send HTML Body email
    By Benjamin2008 in forum Excel General
    Replies: 1
    Last Post: 05-01-2010, 05:29 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