Use Excel to send email with proper subject title

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
I need the subject name of the email to reflect a certain cell value in Sheets("Master Appraisal").Range("B65"), rather than the attachment name that goes with the email currently.

Below is the code that I have to email the saved name of the attachment as the subject:

Code:
Sub Mail_workbook_1()
    Dim wb As Workbook
    Set wb = ActiveWorkbook
 
 
    If Val(Application.Version) >= 12 Then
        If wb.FileFormat = 51 And wb.HasVBProject = True Then
            MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _
                   "be no VBA code in the file you send. Save the" & vbNewLine & _
                   "file first as xlsm and then try the macro again.", vbInformation
            Exit Sub
        End If
    End If
 
    On Error Resume Next
    wb.SendMail "drmingle@***.com", _
                ActiveWorkbook.Name
    wb.SendMail Sheets("Master Appraisal").Range("F1"), _
                ActiveWorkbook.Name
 
    On Error GoTo 0
End Sub
 
The Workbook.SendMail property has the following properties:

Rich (BB code):
workbookobject.SendMail Recipients, Subject, ReturnReceipt

the last two being optional where Subject will default to filename and ReturnReceipt to False

If therefore you want to set the Subject to be based upon a specific cell then use the same approach as that used already to determine recipient in your 2nd call, ie:

Rich (BB code):
wb.SendMail Sheets("Master Appraisal").Range("F1"), _
                Sheets("Master Appraisal").Range("B65")
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top