Excel Macro for automated emails through outlook

gavstock89

New Member
Joined
Feb 7, 2023
Messages
7
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I have a spreadsheet whereby i want to send an automated email every time I open the file based on a set criteria.

Criteria being -

If column D = "specific text" then send email to column G = "outlook email address" (where the cells in column D and G are in the same row)
Also, once email has been sent, some sort of check so that we don't keep sending the same email every time we reopen the file
I understand I can do this with "hyperlink" formula, but want it automated as soon as spreadsheet is opened.
 
Are you saying that you want the Agreement Ref. in column A in the email body?
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try:
VBA Code:
Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim OutApp As Object, OutMail As Object, srcRng  As Range, status As Range
    Set OutApp = CreateObject("Outlook.Application")
    With ActiveSheet
        .Range("A1").CurrentRegion.AutoFilter 4, "Out of date"
        Set srcRng = .Range("D2", .Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
        For Each status In srcRng
            If .Range("J" & status.Row) <> "Yes" Then
                Set OutMail = OutApp.CreateItem(0)
                With OutMail
                    .To = status.Offset(, 3).Value
                    .Subject = ""
                    .HTMLBody = Range("A" & status.Row)
                    .Display
                End With
            End If
            .Range("J" & status.Row) = "Yes"
        Next status
        .Range("A1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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