Enviar Rango de hoja en cuerpo de mail vía Lotus Notes

Tengo esta macro que envía archivos adjunto via Lotus note, pero necesito que en el body del correo copie el rango de una hoja determinada Ej ( "Hoja1" rango (A1:M100), agrego mi código que funciona:

Sub ENVIARLotusNotes()
Dim UserName As String
Dim MailDbName As String
Dim Recipient As String
Dim ccRecipient As String
Dim ans As String
Dim Attachment1 As String
Dim Maildb As Object
Dim MailDoc As Object
Dim AttachME As Object
Dim Session As Object
Dim EmbedObj1 As Object
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' Abre la Base de Datos de Correos de Notes
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If
' Crea nueva mail y dirección y titulo del mail
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
' Selecciona el rango donde obtenda el correo en la hoja "E-mail"
Recipient = Sheets("E-Mail").Range("A2").Value
MailDoc.SendTo = Recipient
ans = MsgBox("Te gustaría enviar (cc) a otra persona" _
, vbQuestion & vbYesNo, "Enviar Copiar")
If ans = vbYes Then
ccRecipient = InputBox("Ingrese a quien desea copiar el Mail" _
, "Ingrese Dirección e-mail ")
MailDoc.CopyTo = ccRecipient
End If
Set MailDoc = Maildb.CREATEDOCUMENT
Call MailDoc.ReplaceItemValue("Form", "Memo")
'Establecer el Destinatario
Call MailDoc.ReplaceItemValue("SendTo", "[email protected]")
'Establece el Tema
Call MailDoc.ReplaceItemValue("Subject", "DATOS ADJUNTOS")
'Crea y Configura en Contenido del Cuerpo del Correo
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Call Body.APPENDTEXT("")
'Crea el Archivo Adjunto al Correo
Call Body.ADDNEWLINE(2)
Call Body.EMBEDOBJECT(1454, "", "", "Attachment")
'Envía el Correo
'Obtiene la Dirección de correo de la carpeta Enviados
Call MailDoc.ReplaceItemValue("PostedDate", Now())
Call MailDoc.SEND(False)
End With
errorhandler1:
Set Maildb = Nothing
Set MailDoc = Nothing
Set Body = Nothing
Set Session = Nothing
End Sub

1 Respuesta

Respuesta
1

Te puedo ayudar. Pero no es mejor que adjuntes un archivo, en vez de copiar en el body todo ese rango.

es un ejemplo del rango. en si el rango es mas corto pero necesito hacer eso, es por eso la pregunta por que el archivo ya lo adjunta con esta macro, saludos y gracias

Pero supongo que quieres que se vea como una imagen, con el formato de las celdas, no como texto plano

si exacto seria lo ideal como imagen

Hace un tiempo, lo intente, y no pude embeber dentro del correo una imagen, pero mañana cuando este en mi trabajo, y tenga Lotus, te ayudo con gusto, investigando.

Es una pregunta recurrente en los foros de programación, pero nunca he encontrado una respuesta definitiva.

Aunque acabo de encontrár esto http://www.mrexcel.com/forum/excel-questions/518746-send-range-rich-text-body-through-lotus-notes.html que parece funcionar, en teoría insertan en formato html en el body del correo, y obviamente el html soporta el formato de las celdas. Para esto crean un documento de word temporal y de ahi lo pasan al lotus. Si puedes pruébalo, yo mañana lo probare a ver como nos va.

Sub Notes_Email_Excel_Cells2()
Dim NSession As Object
Dim NDatabase As Object
Dim NUIWorkSpace As Object
Dim NDoc As Object
Dim NUIdoc As Object
Dim WordApp As Object
Dim subject As String
subject = "Pasted Excel cells using Word PasteSpecial method " & Now
Debug.Print subject
Set NSession = CreateObject("Notes.NotesSession")
Set NUIWorkSpace = CreateObject("Notes.NotesUIWorkspace")
Set NDatabase = NSession.GetDatabase("", "")
If Not NDatabase.IsOpen Then NDatabase.OPENMAIL
'Create a new Lotus Notes document
Set NDoc = NDatabase.CreateDocument
With NDoc
.SendTo = "[email protected]" 'CHANGE RECIPIENT EMAIL ADDRESS
.CopyTo = ""
.subject = subject
'Email body text, including marker text which will be replaced by the Excel cells
.body = "Text in email body" & vbLf & vbLf & _
"**PASTE EXCEL CELLS HERE**" & vbLf & vbLf & _
"Excel cells are shown above"
.Sabe True, False
End With
'Edit the just-created document to copy and paste the Excel cells into it via Word
Set NUIdoc = NUIWorkSpace.EDITDocument(True, NDoc)
With NUIdoc
'Find the marker text in the Body item
.GotoField ("Body")
.FINDSTRING "**PASTE EXCEL CELLS HERE**"
'.DESELECTALL 'Uncomment to leave the marker text in place (cells are inserted immediately before)
'Copy Excel cells to clipboard
Sheets("Sheet1").Range("A1:E6").Copy 'CHANGE SHEET AND RANGE TO BE COPIED AND PASTED
'Create a temporary Word Document
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False 'True to aid debugging
WordApp.Documents.Add
'Paste into Word document and copy to clipboard
With WordApp.Selection
.PasteSpecial DataType:=10 'Enum WdPasteDataType: 10 = HTML; 2 = Text; 1 = RTF
.WholeStory
.Copy
End With
'Paste from clipboard (Word) to Lotus Notes document
.Paste
Application.CutCopyMode = False
WordApp.Quit SaveChanges:=False
Set WordApp = Nothing
.Send
.Close
End With
Set NSession = Nothing
End Sub

Dale lo pruebo y te comento, muchas gracias :)

Lo probe y no me funciona me tira error de Automatizacion? y cambie una linea

.Sabe True, False por .Save True, False me avisas como te fue saludos.

aquí esta la solución, con este me funciono sin problemas, pero mi duda es como copiar una imagen no por que no me la toma,

Sub Notes_Email_Excel_Cells3()
Dim NSession As Object
Dim NDatabase As Object
Dim NUIWorkSpace As Object
Dim NDoc As Object
Dim NUIdoc As Object
Dim WordApp As Object
Dim subject As String
subject = "Envío Formulario " & Now
Debug.Print subject
Set NSession = CreateObject("Notes.NotesSession")
Set NUIWorkSpace = CreateObject("Notes.NotesUIWorkspace")
Set NDatabase = NSession.GetDatabase("", "")
If Not NDatabase.IsOpen Then NDatabase.OPENMAIL
'Create a new Lotus Notes document
Set NDoc = NDatabase.CreateDocument
With NDoc
.SendTo = "" 'CHANGE RECIPIENT EMAIL ADDRESS
.CopyTo = ""
.subject = subject
'Email body text, including marker text which will be replaced by the Excel cells
.body = "Favor cursar,." & vbLf & vbLf & _
"****" & vbLf & vbLf & _
"Envío de info"
.Sabe True, False
End With
'Edit the just-created document to copy and paste the Excel cells into it via Word
Set NUIdoc = NUIWorkSpace.EDITDocument(True, NDoc)
With NUIdoc
'Find the marker text in the Body item
.GotoField ("Body")
.FINDSTRING "****"
'.DESELECTALL 'Uncomment to leave the marker text in place (cells are inserted immediately before)
'Copy Excel cells to clipboard
Sheets("Hoja1").Range("A1:H25").Copy 'CHANGE SHEET AND RANGE TO BE COPIED AND PASTED
'Create a temporary Word Document
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False 'True to aid debugging
WordApp.Documents.Add
With WordApp.Selection
.PasteSpecial DataType:=10 'Enum WdPasteDataType: 10 = HTML; 2 = Text; 1 = RTF
.WholeStory
.Copy
End With
Application.CutCopyMode = False
WordApp.Quit SaveChanges:=False
Set WordApp = Nothing
.Paste
.Send
.Close
End With
Set NSession = Nothing
End Sub

Saludos

Si!, funciona perfecto, solo cambiar el "sabe" por el "save". Pero no entendí tu pregunta.. ¿quieres adjuntar ahora una imagen?

lo que pasa que en el rango hay una imagen, existe forma que la copie? por que cuando la agrego me tira error de Word. Saludos

http://msdn.microsoft.com/es-es/library/ff197265.aspx

Prueba cambiando el DataType:=9

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas