+ Reply to Thread
Results 1 to 17 of 17

Email a range of excel cells using VBA produces infinite loop HELP

  1. #1
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Question Email a range of excel cells using VBA produces infinite loop HELP

    Hi everyone, this is my first time posting here... I am creating a payroll file in which I am trying to send a range of cells to the emails addresses of our employees. I get it to do everything fine except the loop does not end and ends up reproducing the emails. All help is welcome. My coding constructs may not be the best.
    The excel sheet currently contains 170 rows to be emailed. It will grow so just wanted to put that out there.

    Please Login or Register  to view this content.
    Last edited by kjam; 11-16-2015 at 03:40 PM. Reason: update

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    Welcome to the Forum!

    Where is the code for RangeToHTML ? Please do not leave out the code for other Sub or Function procedures that the macro you posted uses. Problems can occur where you least expect them.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Quote Originally Posted by Leith Ross View Post
    Hello kjam,

    Welcome to the Forum!

    Where is the code for RangeToHTML ? Please do not leave out the code for other Sub or Function procedures that the macro you posted uses. Problems can occur where you least expect them.
    I have updated the above code with what you asked for. Thanks for pointing that out.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    Thanks for posting the additional code. Your macro SendMailsFromList should not run because the For Each Cell loop is missing the statement Next cell.

    The code is confusing but it seems like column "B" is where the email address are. Are there column headers in row 1?

    What are you sending to each person from the worksheet?

  5. #5
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Quote Originally Posted by Leith Ross View Post
    Hello kjam,

    Thanks for posting the additional code. Your macro SendMailsFromList should not run because the For Each Cell loop is missing the statement Next cell.

    The code is confusing but it seems like column "B" is where the email address are. Are there column headers in row 1?

    What are you sending to each person from the worksheet?
    I updated that and it runs in the infinite loop all the same. Correct Column B is where the email addresses are. I will be emailing payroll information for employees. The first row contains the headers.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    Which cells will be emailed to the recipient?

  7. #7
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Quote Originally Posted by Leith Ross View Post
    Hello kjam,

    Which cells will be emailed to the recipient?
    For each employee their corresponding row of information will be sent to them. So for the employee name in row A2 their info will be sent to them - the information extends all the way to column AC. In what way could I make this explanation easier without sending the excel file containing the employee information?

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    Do you want to include the information as a single row or create a new line for each cell, i.e. transpose the data?

  9. #9
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Quote Originally Posted by Leith Ross View Post
    Hello kjam,

    Do you want to include the information as a single row or create a new line for each cell, i.e. transpose the data?
    It should be sent as a single row to each employee.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    Try this macro. I have annotated it to explain what is happening. You may want to change the Send to Display to be sure it works correctly.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 11-13-2015 at 07:33 PM. Reason: Change Subject from a Style To a String

  11. #11
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Quote Originally Posted by Leith Ross View Post
    Hello kjam,

    Try this macro. I have annotated it to explain what is happening. You may want to change the Send to Display to be sure it works correctly.

    Please Login or Register  to view this content.
    I am running it now. It gave me an error message saying that I have used up system resources and I need to close programs running. I don't have much running though.

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    Start the Task Manager and check for multiple instances of Outlook. Afterwards, try running the macro again.
    1. Press CTRL+ALT+DEL keys.
    2. Select "Start Task Manager"
    3. Click the "Processes" tab and look for OUTLOOK.EXE
    4. Left Click any Outlook processes
    5. Right Click and select "End Process"
    6. Repeat until all Outlook processes are gone.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    I found the problem. Sorry, bad editing on my part. In the Dim statements, the variable Subject is incorrectly typed as a Style. It should be a String. I made the correct to the code in post #10.

  14. #14
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Quote Originally Posted by Leith Ross View Post
    Hello kjam,

    I found the problem. Sorry, bad editing on my part. In the Dim statements, the variable Subject is incorrectly typed as a Style. It should be a String. I made the correct to the code in post #10.
    I made the changes already Just to get rid of that error message regarding the used up resources.
    error.jpg
    Last edited by kjam; 11-13-2015 at 08:57 PM. Reason: upload error

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    Do you which line of the code generates the error?

  16. #16
    Registered User
    Join Date
    10-09-2015
    Location
    JAMAICA
    MS-Off Ver
    2010
    Posts
    8

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Quote Originally Posted by Leith Ross View Post
    Hello kjam,

    Do you which line of the code generates the error?
    I am getting it at '.Display' or for what you had in the original code '.Send' (ln 75)
    It doesn't happen immediately, It happens after about generating 90+ emails. But it never does all emails.
    Last edited by kjam; 11-13-2015 at 09:51 PM.

  17. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Email a range of excel cells using VBA produces infinite loop HELP

    Hello kjam,

    There are several causes of this error in Outlook. If you have an anti-virus program running, you may want to turn it off temporarily to see if that clears the error.

    Other causes could be viruses, spyware, or registry errors. If you have a program that will defragment your registry, I would do that first.

+ 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 Worksheet Tab Rename Macro Causing Excel Infinite Loop
    By rbrookov in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-07-2014, 08:10 PM
  2. [SOLVED] Excel Crash During (Shouldn't be infinite) While Loop
    By publius190 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2014, 12:21 PM
  3. Problem using loop for sending excel range in email body using Range to HTML code
    By drajanm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-24-2012, 03:17 AM
  4. Replies: 0
    Last Post: 10-04-2012, 10:06 AM
  5. Why is my loop infinite, and how can I fix it?
    By Mrowe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-13-2012, 02:48 PM
  6. Excel 2007 - Print Macro - Infinite Loop Issue
    By Fraenk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2012, 07:50 AM
  7. Infinite Loop
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-12-2010, 10:44 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