0
I created a macro to send different images in the body of the email to different people. The problem is that I am not able to leave the dynamic image in the body of the email. It is attaching right, each image to its respective email. The problem is when I ask to leave visible the image does not open, staying blank or error. Follow the code I’m using:
Function Saudacao() As String
Dim hora As Date
hora = Format(Now, "HH:MM:SS")
Select Case hora
Case "00:00:00" To "11:59:59"
Saudacao = "Bom dia!"
Case "12:00:00" To "17:59:59"
Saudacao = "Boa Tarde!"
Case Else
Saudacao = "Boa Noite!"
End Select
End Function
Sub Enviar_Email()
On Error GoTo TRATAR_ERRO
Range("A5").Activate
Assunto = Range("R1").Value
Mensagem = Range("R3").Value
Do While ActiveCell.Value <> Empty
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = "[email protected]"
.Display
.To = ActiveCell.Value
.CC = ActiveCell.Offset(0, 2).Value
.BCC = ""
.Subject = Assunto & ActiveCell.Offset(0, 1).Value
.Attachments.Add ActiveCell.Offset(0, 3).Value, , 1
.HTMLBody = "<BR>" & ActiveCell.Offset(0, 1).Value & ", " & Saudacao & "<BR><BR>" & Mensagem & "<BR><BR>" & "<img src='ActiveCell.Offset(0, 3).Value'>" & "<BR>" & "Att," & "<BR>" & .HTMLBody
.Send
End With
ActiveCell.Offset(1, 0).Select
ActiveCell.Activate
Set OutMail = Nothing
Set OutApp = Nothing
Loop
On Error GoTo 0
MsgBox "E-mails enviados com sucesso!", bvinformation, "Ok"
Exit Sub
TRATAR_ERRO:
Dim sErro As String
sErro = Err.Number & vbNewLine & Err.Description
MsgBox sErro, vbCritical + vbOKOnly, "Enviar_email"
End Sub
I tried to do this in powershell and also could not, I was only able to put image in the body of the email when I refer to it as link in HTML format, I hope someone posts the answer.
– Ricardo Bohner