Email 'Do It All Super' Button

Jojothemonk3y

New Member
Joined
Feb 1, 2017
Messages
5
Hello!

I would like to send an email from excel that has a pre-populated body of text that but also pulls some data from an excel sheet to populate parts of the email.

So for example, you would click the macro....a prompt would ask for a row number and based on that, the email box would pop with a prewritten body that would pull information from specified columns in the sheet that completes certain sentences (eg Your order ref (contents of B4)). Additionally it would also attach a specified document from a local drive It wouldn't need to populate the email address.

I'm not sure if this is possible? Any ideas?

Thanks in advance!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try something like this. MyRow stores the selected row, and you can build up your message in MyMsg using HTML. The message in the example is very basic, but you can use the same HTML elements as you would find in webpages. I've used a fixed email address to send to, but you could pick this up from the spreadsheet too.
Code:
<hmtl>[COLOR=#000000][FONT=-apple-system]Dim OlObj As Object[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]Set OlObj = CreateObject("Outlook.Application")[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]Set OlItem = OlObj.CreateItem(olMailItem)[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]Set OlAttachments = OlItem.Attachments[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]MyRow = InputBox("Enter row number")[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]With OlItem[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system].To = "[/FONT][/COLOR][EMAIL="name.surname@company.com"]name.surname@company.com[/EMAIL][COLOR=#000000][FONT=-apple-system]"[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system].Subject = "Email Subject"[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]MyMsg = "<hmtl>"</hmtl>[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]MyMsg = MyMsg & "Your order ref: " & Range("B" & MyRow).Value & 
"[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]MyMsg = MyMsg & ""[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system].HTMLBody = MyMsg[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system].Send[/FONT][/COLOR]
[COLOR=#000000][FONT=-apple-system]End With[/FONT][/COLOR]

EDIT: Please ignore the "<html>" at the start of the first line of the code, as well as the "</html>" at the end of this note! I didn't type them, and they don't appear when I try to edit the message - but for some reason they are being added when I submit the post!</hmtl>
 
Last edited:
Upvote 0
Sorry, the code is still being displayed incorrectly - I'll try again!
Code:
Dim OlObj As Object
Set OlObj = CreateObject("Outlook.Application")
Set OlItem = OlObj.CreateItem(olMailItem)
Set OlAttachments = OlItem.Attachments
MyRow = InputBox("Enter row number")
With OlItem
.To = "name.surname@company.com"
.Subject = "Email Subject"
MyMsg = "<hmtl>"
MyMsg = MyMsg & "<p>Your order ref: " & Range("B" & MyRow).Value & "</p>"
MyMsg = MyMsg & "</html>"
.HTMLBody = MyMsg
.Send
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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