Solved EXCEL VBA: SENT EMAIL WITH LAST RECORD CREATED IN THE BODY (1 Viewer)

georg0307

Registered User.
Local time
Today, 10:46
Joined
Sep 11, 2014
Messages
91
Dear All,

In the attached file I have create a button, that sent to me an email and save / close workbook.

I'd like to place in the body (strbody) last record created from the user.

Is it possible?

Thanks in advance

best regards,
 

Attachments

  • Copia di ISSUES.zip
    18.4 KB · Views: 212

Gasman

Enthusiastic Amateur
Local time
Today, 09:46
Joined
Sep 21, 2011
Messages
14,050
I do not believe you can use .EntrireRow like that.
I'd find the last column used and loop, concatenating each cell value with something like a pipe symbol "|".

To save anyone else having to download and unzip just to see a few lines of code.

Code:
Sub Pulsante1_Click()




    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    strbody = "LAST RECORD ISSUED " & vbNewLine & vbNewLine & _
              ThisWorkbook.Name & vbNewLine & _
              "was modified by " & vbNewLine & _
              Environ("username") & _
              Range("A" & Rows.Count).End(xlUp).EntireRow.Text


    On Error Resume Next
    With OutMail
        .To = "xxxxxxx@gmail.com"
        .CC = ""
        .BCC = ""
        .Subject = "File opened"
        .Body = strbody
        .Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
    
    ActiveWorkbook.Close SaveChanges:=True
    
End Sub
 
Last edited:

georg0307

Registered User.
Local time
Today, 10:46
Joined
Sep 11, 2014
Messages
91
Gasman,

my ignorance is absolute sorry, but I don't understand... do you mean that is not possible email last record content in the body?
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:46
Joined
Sep 21, 2011
Messages
14,050
Gasman,

my ignorance is absolute sorry, but I don't understand... do you mean that is not possible email last record content in the body?
Well if it is, I could not find out how. :(
I found how you can copy the range to another range, but that was it. :(

So I would (if I had to) find the last column of data (or hard code it if will never change), then loop through each cell in the row, concatenating to a string variable, separating each value with a character(s) that will never be part of the data.
Then concatenate that string variable to the body as you have tried with the Range.
 

Isaac

Lifelong Learner
Local time
Today, 02:46
Joined
Mar 14, 2017
Messages
8,738
Dear All,

In the attached file I have create a button, that sent to me an email and save / close workbook.

I'd like to place in the body (strbody) last record created from the user.

Is it possible?

Thanks in advance

best regards,

Yes.
 

Users who are viewing this thread

Top Bottom