vBA Outlook Script

Lukums

Board Regular
Joined
Nov 23, 2015
Messages
195
Morning guys,

I have the attached script (obtained from the NET this isn't mine).
It works as intended no issues however, I wish to manipulate it to do the following:

Once that line has converted into an email I wish to place a "1" against that row in column H.
If the script runs again it won't run if that line contains >= 0

The issue I have is I don't know how to add to:

If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then

Parameter to say - also look at Column H for a value.

VBA Code:
Sub test()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim i As Long
    
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    
    On Error GoTo cleanup
    For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Value Like "?*@?*.?*" And _
        LCase(Cells(cell.Row, "C").Value) = "yes" Then

           
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = cell.Value
                .Subject = "Reminder"
                .Body = "Dear " & Cells(cell.Row, "A").Value _
                      & vbNewLine & vbNewLine & _
                        "Please contact us to discuss bringing " & _
                        "your account up to date"
            
                .Send
            End With
            On Error GoTo 0
            Set OutMail = Nothing
            
            End If

Next cell
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub

Many thanks.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
So run only if H is 0, and add a 1 after the code runs?


VBA Code:
Sub test()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim i As Long
   
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
   
    On Error GoTo cleanup
    For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
    If cell.Value Like "?*@?*.?*" And LCase(Cells(cell.Row, "C").Value) = "yes" And Cells(cell.Row, "H").Value = 0 Then  '''here

          
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = cell.Value
                .Subject = "Reminder"
                .Body = "Dear " & Cells(cell.Row, "A").Value _
                      & vbNewLine & vbNewLine & _
                        "Please contact us to discuss bringing " & _
                        "your account up to date"
           
                .Send
            End With
            On Error GoTo 0
            Set OutMail = Nothing
           
            End If

Cells(cell.Row, "H").Value = 1   '''here
Next cell
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top