Chrissyb173
New Member
- Joined
- Jul 21, 2015
- Messages
- 3
Hello there!
I have created a macro which will create a draft email and save it, with an attachment, in a specified folder. This has been looped in order to recreate this process a few hundered times if necessary.
The macro works well with the first email however when it goes to attach the second attachment to the second email, it also attaches the first attachment. The same happens with the third line of data where the macro attaches the first and second attachment as well as the third.
Does anyone know how to get the macro to just attach the latest attachment?
Here's my macro....
Any help would be greatly appreciated - thanks!
I have created a macro which will create a draft email and save it, with an attachment, in a specified folder. This has been looped in order to recreate this process a few hundered times if necessary.
The macro works well with the first email however when it goes to attach the second attachment to the second email, it also attaches the first attachment. The same happens with the third line of data where the macro attaches the first and second attachment as well as the third.
Does anyone know how to get the macro to just attach the latest attachment?
Here's my macro....
Code:
Sub Email_Save_In_Folder()
Dim OutApp As Object
Dim OutMail As Object
Dim x As Integer
x = 1
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Do While Cells(x, 1).Value > 1
With OutMail
.to = Cells(x, 2).Value
.CC = ""
.BCC = ""
.Subject = "Payroll Reports - " & Cells(x, 1).Value
.HTMLBody = "<BODY style=font-size:12pt;font-family:Arial>Hello,<p>Please see the attached Payroll Reports for this month.<p>Many thanks,<p>Schools Service Centre</BODY>"
.Attachments.Add ("[URL="file://\\chesfs05\CSPayroll\Support\Academy"]\\chesfs05\CSPayroll\Support\Academy[/URL] Downloads\16-17TEST\" & Format(Date, "MM.YYYY - MMMM") & "\LBA\" & Cells(x, 1).Value & "\" & Cells(x, 1).Value & ".zip")
.SaveAs ("[URL="file://\\chesfs05\CSPayroll\Support\Academy"]\\chesfs05\CSPayroll\Support\Academy[/URL] Downloads\16-17TEST\" & Format(Date, "MM.YYYY - MMMM") & "\LBA\" & Cells(x, 1).Value & "\" & Cells(x, 1).Value & ".msg")
End With
x = x + 1
Loop
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Any help would be greatly appreciated - thanks!