Send Report as Email body (1 Viewer)

meiteniite89

New member
Local time
Today, 16:43
Joined
Aug 13, 2020
Messages
23
Hello,

I have generated report from form and I need it to be dent in the body of the email.
Is it possible?
I have read loads of threads and put together this, see below.

Currently it sends an attachment from my computer, but not report. I know there is a lot wrong, but I just figure it out.
Code:
        Dim olApp As Outlook.Application
        Dim olMail As Outlook.MailItem

        'get application
        On Error Resume Next
        Set olApp = GetObject(, "Outlook.Application")
        If olApp Is Nothing Then Set olApp = New Outlook.Application
        On Error GoTo 0

        Set olMail = olApp.CreateItem(olMailItem)
        With olMail
        .Subject = "My email with attachment"
        .Recipients.Add "carl.sutcliffe@cummins.com"
        .Attachments.Add "C:\Users\jy871\Desktop\front page.xlsm"
        .Body = "Here is an email"
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:43
Joined
Oct 29, 2018
Messages
21,358
Hi. Are you saying you want the form or report embedded as an image in your email?
 

meiteniite89

New member
Local time
Today, 16:43
Joined
Aug 13, 2020
Messages
23
Hi. Are you saying you want the form or report embedded as an image in your email?
I just want report to be displayed in the body of the email. Text of report.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:43
Joined
May 7, 2009
Messages
19,169
do you need to send the xlsm file as your email body.
you can convert it to text:
and use it as the .Body of your email:
Code:
.Body = ReadTextFile("thePathAndFilenameOfTextfile")
add this another function:
Code:
Public Function ReadTextFile(ByVal strPathFile As String)
    With CreateObject("Scripting.FileSystemObject")
        ReadTextFile = .OpenTextFile(strPathFile, 1, True, -20).ReadAll
    End With
End Function
 

meiteniite89

New member
Local time
Today, 16:43
Joined
Aug 13, 2020
Messages
23
do you need to send the xlsm file as your email body.
you can convert it to text:
and use it as the .Body of your email:
Code:
.Body = ReadTextFile("thePathAndFilenameOfTextfile")
add this another function:
Code:
Public Function ReadTextFile(ByVal strPathFile As String)
    With CreateObject("Scripting.FileSystemObject")
        ReadTextFile = .OpenTextFile(strPathFile, 1, True, -20).ReadAll
    End With
End Function
It was xlsm file, but it was just to trial it out.
Maybe there is a way to put Report into a body of the email?
 

meiteniite89

New member
Local time
Today, 16:43
Joined
Aug 13, 2020
Messages
23
do you need to send the xlsm file as your email body.
you can convert it to text:
and use it as the .Body of your email:
Code:
.Body = ReadTextFile("thePathAndFilenameOfTextfile")
add this another function:
Code:
Public Function ReadTextFile(ByVal strPathFile As String)
    With CreateObject("Scripting.FileSystemObject")
        ReadTextFile = .OpenTextFile(strPathFile, 1, True, -20).ReadAll
    End With
End Function
ReadTextFileline throwns an error. Error code 5.
 

Extra_Cover

Registered User.
Local time
Today, 16:43
Joined
Oct 21, 2008
Messages
71
Try .HTMLBody. You will need to enable Microsoft HTML Object Library in VBA References.

Code:
bdy = "<img src=" & "pathandfilenameofyourreport" & " alt=""Logo"" title=""Logo"" style=""display:block"" width=""1240"" height=""1000"" />"

.HTLMBody = bdy

I have just completed a mass mail system and this works for me, although my file type is .jpg.
 

Users who are viewing this thread

Top Bottom