+ Reply to Thread
Results 1 to 7 of 7

Exception Handling of invalid email address

  1. #1
    Registered User
    Join Date
    10-11-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    21

    Exception Handling of invalid email address

    Hi,

    I am trying to email a list of people using Macro. I have the list in a column and I am looping through the column to email each one with a specified message coming from another column on the same worksheet.

    I do have the email macro going well but I have a question. If the email is incorrect, the macro halts on that email. I want to do some exception handling for the same. Can you suggest something ?

    Also I am a newbie to the excel macro world, so i am pasting my code for your verification and suggestion for modification and enhancement.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Exception Handling of invalid email address

    In general the way that you do exception handling is
    Please Login or Register  to view this content.
    wrap this around the code you want to handle. Hope this helps.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  3. #3
    Registered User
    Join Date
    10-11-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Exception Handling of invalid email address

    Can you tell me when i use a cells.find and if the value is not found how to do the error handling ?

    Also, what does this do

    If Not c Is Nothing Then c.Select

    c is defined as range

  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: Exception Handling of invalid email address

    Hello ncduke,

    In this case, you don't need error handling. The range Find method returns one of two possible values. If the value is found then the cell, itself a Range object, will be returned. If not then the special Object value Nothing is returned.

    By assigning a range object variable to the Find operation, you can then test the result and avoid an error. I have made the needed changes to your code and included comments. Here is the revised macro.
    Please Login or Register  to view this content.
    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!)

  5. #5
    Registered User
    Join Date
    10-11-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Exception Handling of invalid email address

    Thanks Leith,

    I am sure your enhancements are very apt and I have learnt from it.

    I do have a question though.

    In the "for" loop, once the email is ready to be sent, what happens is that if the email address is incorrect, the macro will hang, because there is a lotus notes error (saying something like the email address is not found or something similar to that). How can I trap that exception and handle it appropriately.

    Ideally, what I would want is to open a new sheet and copy that row with incorrect address onto a new sheet in the same workbook, and continue with the next PI_Name

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Exception Handling of invalid email address

    Here's a UDF that tests for a valid email address
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Registered User
    Join Date
    10-11-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Exception Handling of invalid email address

    Can you explain how this works and how should I incorporate it into my code

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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