Hello.
Please help me with this.
I am trying to create a macro in which i can send different files to different emails.
I was looking in this site and others and i came up with this code.
================================
Sub asddddddddddddd()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim i As Integer
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 "?*@?*.?*" 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"
.Attachments.Add ThisWorkbook.Sheets("Sheet1").Range("C" & i)
.Send 'Or use Display.
End With
On Error GoTo 0
Set OutMail = Nothing
Set oMail = Nothing
Set oApp = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
==========================================
In column A I put the name of the person
B the emails
C the file path
The problem is that when i run the macro, no attachment is sent, but the rest of the message is.
I do not know why
Can you help me
Please help me with this.
I am trying to create a macro in which i can send different files to different emails.
I was looking in this site and others and i came up with this code.
================================
Sub asddddddddddddd()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim i As Integer
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 "?*@?*.?*" 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"
.Attachments.Add ThisWorkbook.Sheets("Sheet1").Range("C" & i)
.Send 'Or use Display.
End With
On Error GoTo 0
Set OutMail = Nothing
Set oMail = Nothing
Set oApp = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
==========================================
In column A I put the name of the person
B the emails
C the file path
The problem is that when i run the macro, no attachment is sent, but the rest of the message is.
I do not know why
Can you help me