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
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
.Subject = "New Purchase Order " & Range("H" & Rows.Count).End(xlUp).Value
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Well, this gives me the correct text

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

Watch MrExcel Video

Forum statistics

Threads
1,123,385
Messages
5,601,331
Members
414,446
Latest member
CRAVIN

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
Top