Hi Everyone
I get the following Error when running the below code,
Can you help please ?
Thanks
"Can Find Project or Library"
Sub sendMailv3()
'On Error Resume Next
Dim TempFilePath As String 'location of temp image
Dim imgRNG As String 'area for image
Dim i As Integer 'loop for number of emails
Dim j As Long ' current row
Dim objOutlook As Object
Dim objMail As Object
Dim rngEntry As Range
Dim rngEntries As Range
With Application
.Calculation = xlManual
.ScreenUpdating = False
.EnableEvents = False
End With
Set objOutlook = Outlook.Application
Set rngEntries = ActiveSheet.Range("k1:k3") '<--Change range to your email address range
For Each rngEntry In rngEntries
'''''''Original Code
'''''''For i = 1 To Application.WorksheetFunction.CountA(Range("D:D"))
'''''''loop to count amount of Regions which is 5(works with current template, change if necessary)
i = i + 1
'loop to count amount of Regions which is 5(works with current template, change if necessary)
If i = 1 Then
imgRNG = "A" & i & ":H" & Range("d1").End(xlDown).Offset(0, 1).End(xlUp).Row
j = Range("D1").End(xlDown).Row
'set image range and image height
Else
imgRNG = "A" & j & ":H" & Range("d" & j).End(xlDown).Offset(0, 1).End(xlUp).Row
j = Range("D" & j).End(xlDown).Row
'set image range and image height
End If
Set objMail = objOutlook.CreateItem(0) '1-Appointment 3-Task
With objMail
.To = rngEntry.Value
.CC = "me@email.com"
.Subject = "Statement June"
'& "<p class=style2><span LANG=EN><font FACE=Calibri SIZE=3.5>" _
.HTMLBody = "<span LANG=EN>" _
& "<body><strong><span style='font-size:12.0pt;font-family:Calibri;color: Blue'>" _
& "Hello " & rngEntry.Offset(0, 2).Value & "," _
& "<br><br> Please find attached, statement of Accounts as of 30.06.15." _
& "<br><br> if you have any questions, with regards to your accounts, Please do not hesitate to contact me" _
& "<br><br> Kind Regards" _
& "<br> Brahim Moustaj Credit Control :<BR>"
'first we create the image as a JPG file
Call createJpg("Email", imgRNG, "MailAttach")
'we attached the embedded image with a Position at 0 (makes the attachment hidden)
TempFilePath = Environ$("temp") & "\"
.Attachments.Add TempFilePath & "MailAttach.jpg", olByValue, 0
'Then we add an html <img src=''> link to this image
.HTMLBody = .HTMLBody & "<br><B>Outstanding Payments:</B><br>" _
& "<img src='cid:MailAttach.jpg'<br>" _
& "<br>Your prompt payment is appreciated.<br><br> Thank you,<br>Mike Ham</font></span>"
.Display
'.Send
End With
Next rngEntry
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngEntry = Nothing
Set rngEntries = Nothing
End Sub
Bookmarks