Emails from Excel (via VBA)

Rile1

New Member
Joined
Aug 7, 2018
Messages
6
Hi

Need your assistance on this

I have the following table and I am trying to
- automatically send an email via Excel based on the Status (Column 5) to the Travel Asst. (Column 22, as 1st notification point) and Travel Manager (Column 23, as escalation)
- in the escalation, copy the Travel Asst. and the copy the Travel Manager
- if there is a possibility to select a range of columns, and keep it in the body of the email (just a wish list)

Table
123452223
DateStatusTravel Asst. NameBooking Asst. NameStatusTravel Asst. EmailTravel Manager Email
27-Aug-18Pending BookingABC123Escalation to Travel Managerabc@gmail.com123@gmail.com
27-Aug-18Pending Presentation DEF4561st Notification to Travel Asst.yxz@gmail.com345@gmail.com
27-Aug-18Pending PresentationZXY7892nd Notification to Travel Asst.abc@gmail.com123@gmail.com
27-Aug-18Pending PaymentKLM101Escalation to Booking Manageryxz@gmail.com345@gmail.com

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

The code that i am trying to use for the same is the following
(Note: i am not sure if it is correct, as i tried to understand it from the web and modify it)

The error that displays when i try to run it is
Run- Time error"-2147467259 (80004005)':
We need to know who to send this to. Make sure you enter at least one name.

Note: there are 49 columns in the workbook

Start Code

Sub SendEscalationtoTravelManagerMail()
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim iCounter As Integer
Dim MailDest As String


Set OutLookApp = CreateObject("OutLook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)


With OutLookMailItem
For iCounter = 1 To WorksheetFunction.CountA(Columns(49))
If MailDest = "1st Notification to Travel Asst." And Cells(iCounter, 5) = "1st Notification to Travel Asst." Then
MailDest = Cells(iCounter, 22).Value
ElseIf MailDest = "2nd Notification to Travel Asst." And Cells(iCounter, 5) = "2nd Notification to Travel Asst." Then
MailDest = Cells(iCounter, 22).Value
ElseIf MailDest = "Escalation to Travel Manager" And Cells(iCounter, 5) = "Escalation to Travel Manager" Then
MailDest = MailDest & ";" & Cells(iCounter, 23).Value
End If
Next iCounter


.BCC = MailDest
.Subject = "Pending Booking"
.Body = "Reminder: Booking is due. Please complete."
.Send
End With


End Sub

End Code

Please if somebody could assist me on this

Thanking you
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi Dave

Thanks for advising but I was not to clear on the same
I tried to amend the BCC to To but still it is unable to email

.To = MailDest
.Subject = "Pending Booking"
.Body = "Reminder: Booking is due. Please complete."
.Send

Please advise on the above to the "To" is to be added or is it on a different section

Thanking you
 
Upvote 0
Code:
 If MailDest = "1st Notification to Travel Asst." And Cells(iCounter, 5) = "1st Notification to Travel Asst." Then
"MailDest" is not set so the criteria will never be met.

Possibly seeing if the cell.value = "1st Notification to Travel Asst." then adding the e-mail address to the string would be a solution.

for example:
To find the email addresses for "1st Notification to Travel Asst."
Code:
        For iCounter = 1 To WorksheetFunction.CountA(Columns(49))
            If Cells(iCounter, 5) = "1st Notification to Travel Asst." Then
                MailDest = Cells(iCounter, 23).Value & ";" & MailDest
            End If
        Next iCounter
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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