Jyggalag
Active Member
- Joined
- Mar 8, 2021
- Messages
- 445
- Office Version
- 365
- 2019
- Platform
- Windows
Hi all,
I have this code attached to a macro:
The macro used to work, but when I use it down it rebugs and highlights this:
This is the file by the way:
So the attachment cell is located in cell F2
I have this code attached to a macro:
VBA Code:
Option Explicit
Private Const FilePath As String = "R:\LXI_DLL\ZGJ_COMMON\FLD COMP FOLDER\12-FOLDER\TOPIC 2\ATTACHMENTS\"
Sub send_email_complete()
Dim OutApp As Object
Dim OutMail As Object
Dim i As Long
Dim ws As Worksheet
Dim col As New Collection, itm As Variant
Dim ToAddress As String, CCAddress As String, EmailSubject As String
'~~> Change this to the relevant worksheet
'~~> that has the emails (right now Search Export has it)
Set ws = ThisWorkbook.Sheets("Search Export")
Set OutApp = CreateObject("Outlook.Application")
Dim BodyText As String
BodyText = ws.Range("G2") & "<BR>" & "<BR>" & _
ws.Range("G4") & "<BR>" & _
ws.Range("G5") & "<BR>" & _
ws.Range("G6") & "<BR>" & "<BR>" & _
ws.Range("G8") & "<BR>" & "<BR>" & _
ws.Range("G10") & "<BR>" & "<BR>" & _
"<b>" & ws.Range("G12") & "</b><br>" & "<BR>" & _
ws.Range("G14") & "<BR>" & _
ws.Range("G15")
Dim AttachmentName As String
AttachmentName = FilePath & ws.Cells(2, 6).Value2
For i = 2 To ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'~~> Constructing addresses and subject
ToAddress = ws.Cells(i, 2).Value2 & ";" & ws.Cells(i, 3).Value2 & ";" & ws.Cells(i, 4).Value2
CCAddress = ws.Cells(i, 5).Value2
EmailSubject = ws.Cells(i, 1).Value2
'~~> This creates a new email (so we can send out multiple emails)
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = ToAddress
.CC = CCAddress
.Subject = EmailSubject
.HTMLBody = BodyText
.Attachments.Add AttachmentName
.Send
End With
Next i
End Sub
The macro used to work, but when I use it down it rebugs and highlights this:
This is the file by the way:
So the attachment cell is located in cell F2