Email from MS Excel

With thanks to another poster I've managed to get the code below opening and sending an email from MS Excel.

The only problem I'm having is I want the value from a particular cell in a worksheet to appear in the message body. This value is actually a formula and will change as the source worksheet changes hence it will differ each time an email is sent i.e. the value at time of sending will convey the message I require.

My unsuccessful attempt is shown in the blue text, below.

Any advice would be greatly appreciated.

Thanks

Sub Email1()
' create a new Outlook Application Object,
' direct it to the proper NameSpace,
' c reate a new Mail Item and set the attachments collection

Dim theApp, theNameSpace, theMailItem, myAttachment, MessageBody, subject

Set theApp = CreateObject("Outlook.Application")
Set theNameSpace = theApp.GetNameSpace("MAPI")
Set theMailItem = theApp.CreateItem(0)
theMailItem.Display
Set myAttachment = theMailItem.attachments
MessageBody = "Purchase Order Requisition Number" & Worksheets(Macros).Range("d63").Select & " is awaiting your review and upload into Arrow"
subject = "Purchase Order Requisition"

'add recipients to MailItem

theMailItem.Recipients.Add (
xyz@xyz.com.nz)
theMailItem.subject = subject
theMailItem.Body = MessageBody
theMailItem.Send
theNameSpace.Logoff
End Sub




Answer this question

Email from MS Excel

  • TimSE

    Many thanks Derek. All is now working as required.

  • Mjman15

    Hi Bocman,

    Try Worksheets(Macros).Range("d63").Value, this should return the value in the cell d63 and place it in the email. The value will change with the formula.



  • Email from MS Excel