Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Name Change On Email Subject

Status
Not open for further replies.

DrMingle

Technical User
May 24, 2009
116
US
I need the subject name of the email to reflect a certain cell value,Sheets("Master Appraisal").Range("B65"), rather than the attachment name that goes with the email.

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
 
From VBA help the parameters of sendmail are

expression.SendMail(Recipients, Subject, ReturnReceipt)

replace ActiveWorkbook.Name
with Sheets("Master Appraisal").Range("B65").value

or clearer in my view
Code:
wb.SendMail _
    recipients:="drmingle@***.com" _
    Subject:=Sheets("Master Appraisal").Range("B65").value

Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top