Help!! VBA - getting cell data in subject line of outlook email

Snowsheep91

New Member
Joined
Oct 6, 2014
Messages
4
Hi there,

I'm creating a spreadsheet for work which documents which data we purchase against which projects. Currently all the info gets filled in and then I've created a simple macro with a command button which sends the updated spreadsheet to our finance department. They then have to check to see which was the latest project added to the spreadsheet.

What I want to do is not just create the email, but in the subject line along with the subject 'New Purchase Order', add in the project number which is referenced in the H column. This would be easy for me if it was just one cell (Range "H7") but I want it to pick up the last cell with text in it in that column. Does that make sense?

This is the current VBA:

Sub Mail_workbook_Outlook_1()
Dim OutApp As Object
Dim OutMail As Object


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)


On Error Resume Next
With OutMail
.to = "xyz@zyx.com"
.CC = ""
.BCC = ""
.Subject = "New Purchase Order"
.Body = "Hi XYZ," & vbNewLine & vbNewLine & _
"Please find attached the latest version of the purchase order sheet." & vbNewLine & vbNewLine & "Thanks,"
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
On Error GoTo 0


Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Quick replies appreciated! I'm not very good at VBA so actual codes would be appreciated :)

Thanks,
SS91
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try

Code:
.Subject = "New Purchase Order " & Range("H" & Rows.Count).End(xlUp).Value
 
Upvote 0
Well, this gives me the correct text

Code:
Sub test()
MsgBox "New Purchase Order " & Range("H" & Rows.Count).End(xlUp).Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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