jalrs
Active Member
- Joined
- Apr 6, 2022
- Messages
- 300
- Office Version
- 365
- Platform
- Windows
Good morning guys,
I want to avoid email displaying if cell A2 is blank, because if cell A2 is blank then the sheet is blank and there's no need to display it if I'm not going to send it.
I still have difficulties handling this type of stuff therefore I search for help.
Here is my code:
Any help is greatly appreciated.
Thanks
EDIT: Cell A2 from attachment
I want to avoid email displaying if cell A2 is blank, because if cell A2 is blank then the sheet is blank and there's no need to display it if I'm not going to send it.
I still have difficulties handling this type of stuff therefore I search for help.
Here is my code:
VBA Code:
Option Explicit
Sub mailmacro1()
Dim OutApp As Object
Dim OutMail As Object
Dim ws1 As Worksheet, ws2 As Worksheet
Dim lr As Long, i As Long
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set ws1 = ThisWorkbook.Worksheets("PainelControlo")
Set ws2 = ThisWorkbook.Worksheets("MACRO 1")
ws2.Activate
lr = Cells(Rows.Count, "A").End(xlUp).Row
On Error Resume Next
For i = 2 To lr
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = Cells(i, 2).Value
.CC = Cells(i, 3).Value
.Subject = Cells(i, 4).Value
.Body = Cells(i, 7).Value
.Display
.Attachments.Add ThisWorkbook.Path & "\Controlo e Difusão\Partilhas e Regularizações\" & Cells(i, 5).Value & ".xlsx"
End With
Next i
On Error GoTo 0
Set OutMail = Nothing
ws1.Activate
End Sub
Any help is greatly appreciated.
Thanks
EDIT: Cell A2 from attachment