Send Report as Email body

meiteniite89

New member
Local time
Today, 14:51
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"
 
Hi. Are you saying you want the form or report embedded as an image in your email?
 
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.
 
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
 
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?
 
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.
 
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

Back
Top Bottom