Enviar email con imagen incrustada con macros excel CDO
Tengo un duda y no se como resolverlo, quisiera enviar email con imagen incrustada como pie de página macros excel haciendo uso colección CDO y la codificación es la siguiente:
Private Sub CommandButton3_Click() Application.ScreenUpdating = False Application.DisplayAlerts = False Dim Cuerpo As Range Dim Incidente As Integer Dim MiCorreo As CDO.Message ' Set MiCorreo = New CDO.Message ' With MiCorreo.Configuration.Fields .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "1234567890" .Update End With Asunto = Hoja1.Range("C5").Text Correo = Hoja1.Range("C3").Text CorreoConCopia = Hoja1.Range("C4").Text With MiCorreo .Subject = Asunto .From = "[email protected]" .To = Correo .CC = CorreoConCopia '====================================== '.Attachments.Add TempFilePath .HTMLBody = RangetoHTML(ActiveSheet.Range("A7:D30")) & "<img src=cid:'D:\Aplicaciones vb net\firma.png' height=120 width=170>" '=========================================== End With On Error Resume Next ' MiCorreo.Send ' Set MiCorreo = Nothing ' Incidente = Hoja1.Range("A1000") Incidente = Incidente + 1 Hoja1.Range("A1000").Value = Incidente 'MsgBox "Correo enviado", vbInformation, "WCM" If Err.Number = 0 Then MsgBox "El correo ha sido enviado con éxito", vbInformation, "WIDMAN" Else MsgBox "Se produjo el siguiente error: " & vbNewLine & _ Err.Description, vbCritical, "Error No. " & Err.Number End If Application.DisplayAlerts = False Application.ScreenUpdating = True End Sub Function RangetoHTML(rng As Range) ' Changed by Ron de Bruin 28-Oct-2006 ' Working in Office 2000-2007 Dim fso As Object Dim ts As Object Dim TempFile As String Dim TempWB As Workbook TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm" 'Copy the range and create a new workbook to past the data in rng.Copy Set TempWB = Workbooks.Add(1) With TempWB.Sheets(1) .Cells(1).PasteSpecial Paste:=8 .Cells(1).PasteSpecial xlPasteValues, , False, False .Cells(1).PasteSpecial xlPasteFormats, , False, False .Cells(1).Select Application.CutCopyMode = False On Error Resume Next .DrawingObjects.Visible = True .DrawingObjects.Delete On Error GoTo 0 End With 'Publish the sheet to a htm file With TempWB.PublishObjects.Add( _ SourceType:=xlSourceRange, _ Filename:=TempFile, _ Sheet:=TempWB.Sheets(1).Name, _ Source:=TempWB.Sheets(1).UsedRange.Address, _ HtmlType:=xlHtmlStatic) .Publish (True) End With 'Read all data from the htm file into RangetoHTML Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2) RangetoHTML = ts.readall ts.Close RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _ "align=left x:publishsource=") 'Close TempWB TempWB.Close savechanges:=False 'Delete the htm file we used in this function Kill TempFile Set ts = Nothing Set fso = Nothing Set TempWB = Nothing End Function
La macro funciona pero no logro incrustar la imagen al cuerpo del correo, pero en la parte final seguido de rango de celadas.
Gracias de antemano.
Saludos,
Widman
Lima - Perú