+ Reply to Thread
Results 1 to 2 of 2

The macros doesn't skip the cells that not contain mail on it

  1. #1
    Registered User
    Join Date
    03-29-2021
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    1

    The macros doesn't skip the cells that not contain mail on it

    The macros works perfectly if all the cells have mail, but if a cell doesn't have mail the macros send me an error, how can I fixed that if the cell doesn't have mail skip it and follow to the next row and so on ...


    [Sub EnviarEmail()
    '
    ' Declaramos variables
    '
    Dim OutlookApp As Outlook.Application
    Dim MItem As Outlook.MailItem
    Dim celltxt As String
    Dim Asunto As String
    Dim Correotxt As String
    Dim Destinatario As String
    Dim Actividad As String
    Dim Msg As String
    '
    Set OutlookApp = New Outlook.Application
    '
    'Recorremos la columna EMAIL
    '
    For Each cell In Range("O9:O99")
    '
    'Asignamos valor a las variables
    '
    Asunto = "Actividad Pendiente"
    Destinatario = cell.Offset(0, -1).Value
    Correo = cell.Value
    CAPA = cell.Offset(0, -13).Value
    Actividad = cell.Offset(0, -2).Value
    FechaVencimiento = Format(cell.Offset(0, 1).Value, "dd-mmm-yy")
    '
    'Cuerpo del mensaje
    '
    Msg = "Apreciable: " & Destinatario & vbNewLine & vbNewLine
    Msg = Msg & "Queremos informarle que tiene una actividad pendiente en la CAPA "
    Msg = Msg & CAPA & "." & vbNewLine & vbNewLine
    Msg = Msg & "La actividad a realizar es: "
    Msg = Msg & Actividad & vbNewLine & vbNewLine
    Msg = Msg & "Con fecha compromiso: "
    Msg = Msg & FechaVencimiento & "." & vbNewLine & vbNewLine
    Msg = Msg & "Le pedimos realizar la actividad a la brevedad posible para evitar que esta se venza y caer en incumplimiento " & vbNewLine & vbNewLine
    Msg = Msg & "Atentamente:" & vbNewLine
    Msg = Msg & "Ingenierķa de Calidad"
    '
    Set MItem = OutlookApp.CreateItem(olMailItem)
    With MItem
    .To = Correo
    .Subject = Asunto
    .Body = Msg
    .Send
    '
    End With
    '
    Next
    '
    End Sub]
    Last edited by miguelgamo; 03-29-2021 at 03:21 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: The macros doesn't skip the cells that not contain mail on it

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    If posting code please use code tags, see here.

+ 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. VBA to skip formula if criteria doesn't match
    By dream_life in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2019, 04:05 AM
  2. How can I skip a .PivotItem if it doesn't exist?
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2018, 04:54 PM
  3. Mail Alert if an expected mail (at a specific time daily) doesn't arrives in the inbox
    By dineshsachidananda in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2017, 09:00 AM
  4. VBA Code to Skip to Next Macro if File Doesn't Exist
    By ahankerson2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2015, 01:44 AM
  5. [SOLVED] Macros won't run, doesn't prompt me to enable macros anymore
    By trfountain22 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2015, 01:34 PM
  6. Macros for Mail Range/Selection in the body of the mail along with attachment
    By xenon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-20-2015, 06:29 AM
  7. How to skip rows when referencing another workbook that doesn't skip rows?
    By Julian2501 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-06-2014, 04:55 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