Send a Range of Cells by e-mail

Hello all,

I’ve been trying to send an form by e-mail, but failing to. All I’ve read so far points out that this is impossible to do. I know how to do it with another sheet software, but I need to work it out with Libreoffice Calc.

I need to send a range of cell by email, like the image bellow. The code I’m using is basically “mensagem2 = formulario.getCellRangeByName(“A1:D10”)”. It presents a propriety error, because the body must be a string.

image

I accomplished already a way to send the e-mail, and to get those cell’s contents with them. The whole project will include copy and paste those informations in a database sheet and clear the form’s cells. I didn’t write those lines yet.

I hope someone had this problem and solved it already.

My code bellow:

REM  *****  BASIC  *****

Sub Enviar_eMail

Dim eMail as String
Dim assunto as String
Dim mensagem as String
Dim eMessage as Object 
Dim eMailer as Object
Dim eMailClient as Object

Dim Produto as String
Dim Descricao as String
Dim Tipobaixa as String
Dim OP as String
Dim QnttotalOP as String
Dim Qntjabaixada as String
Dim Qntbaixa as String
Dim Qntscrap as String
Dim Solicitante as String
Dim Obvervacoes as String


formulario = ThisComponent.Sheets.getByName("Formulario")
lgMailClientFlags = com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE
oSystemMail = createUnoService( "com.sun.star.system.SimpleSystemMail" )
oMailClient = oSystemMail.querySimpleMailClient()
oMailMessage = oMailClient.createSimpleMailMessage()

eMail = "gabriel.gauze@company.XXX"
assunto = "teste"

Produto = formulario.getCellRangeByName("B2").string
Descricao = formulario.getCellRangeByName("B3").string
Tipobaixa = formulario.getCellRangeByName("B4").string
OP = formulario.getCellRangeByName("D4").string
QnttotalOP = formulario.getCellRangeByName("B5").string
Qntjabaixada = formulario.getCellRangeByName("D5").string
Qntbaixa = formulario.getCellRangeByName("B6").string
Qntscrap = formulario.getCellRangeByName("D6").string
Solicitante = formulario.getCellRangeByName("B7").string
Observacoes = formulario.getCellRangeByName("A9").string

'mensagem1 = "Produto: " & Produto & Chr$(13) & "Descrição: "& Descricao & Chr$(13) & "OP: " & OP & " | Tipo da baixa: " & Tipobaixa & Chr$(13) & "Qtde total da OP: " & QnttotalOP & " | Quantidade já solicitado baixa: " & Qntjabaixada & Chr$(13) & "Qtde para BAIXAR: " & Qntbaixa & Chr$(13) & "Qtde scrap: " & Qntscrap & Chr$(13) & "Solicitante: "& Solicitante & Chr$(13) & "Observações: " & Observacoes

mensagem2 = formulario.getCellRangeByName("A1:D10")

eMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
eMailClient = eMailer.querySimpleMailClient()
eMessage = eMailClient.createSimpleMailMessage()    
		eMessage.setRecipient(eMail)
		eMessage.setSubject(assunto)
		'eMessage.setAttachement (Array(sAttachmentURL))
		eMessage.Body = mensagem2
		
oMailClient.sendSimpleMailMessage( eMessage, lgMailClientFlags )

End Sub