VBA generated email

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have this code that works well.

is there a way to change the "To" address to the value in a cell within the workbook?

Sheets("Supplier").Range("E8")

Also curious if its possible to a row in the body that would come from a value in a cell.

Code:
Sub GenerateEmail()
'Create Email

  
   If Sheets("Supplier").Range("E8").Value <> "" Then
      With CreateObject("outlook.application").createitem(0)
        .To = "QuoteFiles@drs.com"
        .CC = ""
        .BCC = ""
        .Subject = "Leonardo DRS - Open PO Status Request. Please Complete the attached and Return ASAP"
        .body = "Attched please find Leonardo DRS - NIS PO Status Report.  We formally request you complete the attached Template (Tab: PO Status)and return it to the sender as soon as possible.  If you have any questions, please contact the sender.  We thank you for your continued support"
        .attachments.Add ThisWorkbook.FullName
        .display
     End With
     
     Else
     
     MsgBox " It appears that you did not list a Contact Email address in E5"
     Sheets("Supplier").Range("E8").Select
     
   End If
   

 
End Sub

Thanks for the help!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Like the below, if i inderstand you correctly

VBA Code:
.To = Sheets("Supplier").Range("E8")
.body = "Attched please find Leonardo DRS - NIS PO Status Report. " & vbnewline & Sheets("Supplier").Range("E8") & " more text"
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,499
Members
449,089
Latest member
Raviguru

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