Adding Variable data to an email subject line

Adendum

New Member
Joined
Feb 15, 2021
Messages
24
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I am using this VBA to send a worksheet and I would like to be able to offer an option to add a variable to the subject line so we can distinguish emails...
VBA Code:
Sub SendWorkBook()
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    On Error Resume Next
    With OutlookMail
.Display
.To = "email@email.com"
.CC = ""
.BCC = ""
.Subject = "Training-Project"
.Body = "See attached. Respond ASAP. Thank you."
.Attachments.Add Application.ActiveWorkbook.FullName
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub

So Ideally the user is offered a message box to enter a word or phrase, probably a location, and the subject line appends that word or phrase to it so that the email subject line would read...

"Training-Project (London)" but someone in York would send a mail "Training-Project (York)".
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Excel Formula:
.Subject =  "Training-Project (" & InputBox("Location? e.g. York", "Location Input") & ")"
 
Upvote 0
Excel Formula:
.Subject =  "Training-Project (" & InputBox("Location? e.g. York", "Location Input") & ")"

Kenneth,

That is bordering on brilliant...and so simple...even I can understand it!

The downside is that when the button is clicked the Outlook email window covers the message box. It works but you have to minimise the Outlook email, then enter the details into the message box and switch over to the Outlook window to see the email populated. It works though!

Maybe I should look at generating a message box first when the button is clicked and then open up Outlook? Wonder if I can figure that bit out? Feel free to prompt a novice!

:)
 
Upvote 0
Kenneth,

That is bordering on brilliant...and so simple...even I can understand it!

The downside is that when the button is clicked the Outlook email window covers the message box. It works but you have to minimise the Outlook email, then enter the details into the message box and switch over to the Outlook window to see the email populated. It works though!

Maybe I should look at generating a message box first when the button is clicked and then open up Outlook? Wonder if I can figure that bit out? Feel free to prompt a novice!

:)

Worry not .... now have a message box seen first, takes it's info and dumps in to the subject line.

Very happy bunny here :)
 
Upvote 0
Glad all is well.

Most usually just .Send so no Outlook is shown. Of course if you want the user to edit the email and send it themselves, then .Display is best.
 
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,769
Members
448,991
Latest member
Hanakoro

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