Macro al copiar rango mantenga el formato al pegar cuerpo de correo.
Tengo este código, donde lo que hace es copia un rango del excel y lo pega en el cuerpo del correo.
El drama es que llegue hasta que respete los colores y las formas, pero los tamaños me los modifica osea si una línea la armo a 3 píxeles la copia al también original del excel.
¿Hay forma de que respete tal cual se la creo en el cuadro del excel? ¿Qué no modifique?
Espero su pronta respuesta.
Sub Mail_SEA_FLETEPAMPA()
Dim nombrearchivo As String
Dim rng As Range
Dim Arng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim trBody As String
Dim user1 As String
Dim hora As Double
Dim saludo As String
Set rng = Nothing
Set rng = Sheets("hoja1").Range("B9:E15")
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set OutkAttach = OutApp.CreateItem(Attachments)
With OutMail
.To = ""
.CC = "i"
.BCC = ""
.Subject = "SEA_Fletes:/" & Sheets("PAMPA").Range("C9") & " " & ("Envio N°") & " " & Sheets("PAMPA").Range("C11") & " " & ("Fecha") & " " & Format(Now, "d-m-yy") & " " & Range("C1").Value
.Attachments.Add (nombrearchivo)
.HTMLBody = saludo & RangetoHTML(rng) & strbody
.Display 'or use .Send
End With
End Sub
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2013
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
Dim strbody As String
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, , True, True
.Cells(1).PasteSpecial xlPasteFormats, , True, True
.Cells(1).Select
.DrawingObjects.Delete
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