Macro to open and populate email

Rbubbles

New Member
Joined
Mar 1, 2018
Messages
2
Hi guys,

I'm still relatively new to VBA but I have been following a few threads on here and hope you may be able to help.

I'm currently working on new travel booking spreadsheet for my company and am looking for a macro that will do the following on a selected row.

1) Open a new email message in outlook
2) Fill the "To" field in outlook with the value of column A
3) Fill the body field as per the template below -

Hi [Provider]<o:p></o:p>
<o:p></o:p>
May you please make the following booking?<o:p></o:p>
<o:p></o:p>
Traveldate: (Column C) <o:p></o:p>
Name: (Column D) <o:p></o:p>
Reference number: (Column F) <o:p></o:p>
Contactnumber: (Column M) <o:p></o:p>
<o:p></o:p>
Collection Time: (Column G) <o:p></o:p>
Appointment Time: (Column H) <o:p></o:p>
Collection Address: (Column I) <o:p></o:p>
Destination Address: (Column K) <o:p></o:p>
Return Collection Time: (Column O)

Any help would be greatly appreciated!

Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi,

here's a basic mail to get you started. It has no error handling.
It assumes the worksheet name is Sheet1, change as required.
There's no information for the subject field.
Also not clear whether Provider is the person in column D or someone else. So I left it as [Provider].

It is set up to display the message. You can test it and delete messages. Once ready to send mail, uncomment out .Send. Or leave it
as .Display to give it the eyeball then manually press send on the message.

Test on a workbook copy first!
Code:
Sub SendEmail_22()

Dim EmailSubject As String
Dim SendTo As String
Dim EmailBody As String
Dim ccTo As String
Dim v(1 To 10) As Long
Dim j As Long
Dim i As Long
 
'The following will ask you to enter a number for the email addresses listed in column A into an input box.
 
j = 1
' email addresses assumed to be starting in A2
For i = 2 To 7
   If Sheets("Sheet1").Range("A" & i).Value <> "" Then
   j = i
   boxList = boxList & j & " - " & Sheets("Sheet1").Range("A" & i).Value & " " & vbCr
 
   End If
Next
   RowSelect = InputBox("Enter  number to choose." & vbCr & vbCr & boxList)
 
   MailName = Range("A" & RowSelect).Value
 
'Or use the following if you just want to select the name in column A
  ' RowSelect = ActiveCell.Row
  ' MailName = Range("A" & RowSelect).Value
  
  
  
'EmailSubject = "Put the subject here or use a cell reference"

EmailBody = "Hi [Provider]" & vbNewLine & vbNewLine _
& "Traveldate: " & Range("A" & RowSelect).Offset(0, 2).Value _
& vbNewLine & "Name: " & Range("A" & RowSelect).Offset(0, 3).Value _
& vbNewLine & "Reference Number: " & Range("A" & RowSelect).Offset(0, 5).Value _
& vbNewLine & "Contactnumber: " & Range("A" & RowSelect).Offset(0, 12).Value _
& vbNewLine & "Collection Time: " & Range("A" & RowSelect).Offset(0, 6).Value _
& vbNewLine & "Appointment Time: " & Range("A" & RowSelect).Offset(0, 7).Value _
& vbNewLine & "Collection Address: " & Range("A" & RowSelect).Offset(0, 8).Value _
& vbNewLine & "Destination Address: " & Range("A" & RowSelect).Offset(0, 10).Value _
& vbNewLine & "Return Collection Time: " & Range("A" & RowSelect).Offset(0, 14).Value _


Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = EmailSubject
.To = MailName
.CC = ccTo
.Body = EmailBody
.Display
'.Send
End With


Set App = Nothing
Set Itm = Nothing
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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