Adding a cell value to the "Subject" field in

Phil57

New Member
Joined
Jul 25, 2021
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
Hi all, I have a macro that emails out the selected sheet with a pre-filled "Subject" topic stating Newmont Tanami Latest Damage. What I want to do however is to add in directly after the word Damage the cell text or value in D6 & then directly after D6 followed by I6. Below image shows where I want this and below that is the full code. Can anyone help here

1627270960671.png


Full VBA code below

Sub Mail_ClaimSheet()
'Working in 2000-2010
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'Excel 2007-2010, exit the sub when your answer is
'NO in the security dialog that you only see when you copy
'a sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With


'Save the new temp workbook and mail it
TempFilePath = Environ$("temp") & "\"
TempFileName = ActiveSheet.Name & " " _
& Format(Now, "{dd-mmm-yy}")

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

strbody = "Hello," & vbNewLine & vbNewLine & _
"Please note the attachment for details of the latest damage incident." & vbNewLine & vbNewLine & _
"(NOTE; Please reply to all when responding to this e-mail.)"

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = "phillip.moyses@newmont.com"
.CC = "phillip.moyses@newmont.com"
.BCC = "phillip.moyses@newmont.com"
.Subject = ActiveSheet.Name & " Newmont Tanami Latest Damage"
.Body = strbody
.Attachments.Add Destwb.FullName
.Send
End With
On Error GoTo 0
.Close SaveChanges:=False
End With

'Delete the temp file you have sent
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
It is ok. I found a solution to this. I just had to add in & /Range("D6").Value at the end of my Subject text and it worked.

1627276976252.png
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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