+ Reply to Thread
Results 1 to 7 of 7

Auto email loop with formatted table data breaking on second loop VBA

  1. #1
    Registered User
    Join Date
    12-17-2014
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    14

    Auto email loop with formatted table data breaking on second loop VBA

    Oops, I just realised there is a specific place for vba stuff, I have posted that there now, but No idea how to get rid of this, so I'll just mark solved.... *shrug*

    Hi there,

    I'm not all that fantastic at VBA and most of my work is just Frankenstein'ed,
    The idea is that there is a table with a list of staff, and a number generated by a total count of things in another table in their name
    If that number is a value above 0, an email is constructed in their name and sent, containing a copy of the table on the "reportlookup" worksheet pasted into the body of the email,

    I have two issues...

    1. The first email creates fine, opens up and sends etc, but when the loop goes to start again it breaks at the line 'OtlNewMail.HTMLBody = Signature' with a "object variable or with block not set" error and it doesn't continue with the next email and I cannot work out why.

    2. I have no idea how to get the table in with its formatting, I figured that it had to be a html call rather than just .body to get the formatting, but from there I'm stuck can I grab it from the clipboard? Because the way that my script currently works, the table on the other sheet is sorted to only show the rows I want in the email, which is a filter on 4 columns which i have in the 'GET TABLE DATA FOR EMAIL section, and then the first 4 columns x all rows inside the table is what I want in the body. but the amount of rows that contains varies quite a lot, so I can't just static reference a range.


    I managed to come up with this so far:


    Please Login or Register  to view this content.

    Any help would be much appreciated

    Thank you very much in advance.

    Regards,
    Josh
    Last edited by Who_else; 03-23-2016 at 08:20 PM. Reason: Oops

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Auto email loop with formatted table data breaking on second loop VBA

    For your first issue, you need to create a new email every time i.e. put these two lines...

    Please Login or Register  to view this content.
    below this line...
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Auto email loop with formatted table data breaking on second loop VBA

    I haven't tested it... but try this that I picked up from elsewhere:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-17-2014
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    14

    Re: Auto email loop with formatted table data breaking on second loop VBA

    Wow,

    So quick,

    that seems to work really well except for the Set rng = Selection statement seems to ignore the filters in the range, despite them definitely being active and working.

    I'm not really sure how to work around that.

    Thanks -

    Josh

  5. #5
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Auto email loop with formatted table data breaking on second loop VBA

    Hi Josh,

    I can't take all the credit. I copied the extra funtion from elsewhere, although I have used something similar previously.
    To fix your issue, try this...

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-17-2014
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    14

    Re: Auto email loop with formatted table data breaking on second loop VBA

    FANTASTIC,

    That ended up pasting the report as requested in, but it still had the conditional formatting of the original table inside it, and it also wasn't listed as a table, so I chucked in:

    Please Login or Register  to view this content.
    to the temp file created inside that function
    Which cleaned it all up very nicely and made it much easier to read for the outgoing email,

    Thank you so much for your help in this matter!

    1x gold star and an Easter egg to you!

  7. #7
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Auto email loop with formatted table data breaking on second loop VBA

    No problems, glad I could help

+ 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. Loop through table and send individual report by email
    By eagleadam89 in forum Access Tables & Databases
    Replies: 1
    Last Post: 03-10-2016, 12:58 PM
  2. Breaking loop if condition met
    By kaderk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2015, 11:09 AM
  3. [SOLVED] Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-14-2014, 09:32 AM
  4. Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2014, 04:59 PM
  5. LOOP formula breaking
    By donyc in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-08-2012, 04:28 PM
  6. Breaking out of a loop
    By hojkoff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2010, 07:29 AM
  7. Breaking a Find Loop
    By Jmoo in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2010, 10:55 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