I have this code here:
Sub send_Email()
Dim i As Long
Dim h As Long
Dim OutApp, OutMail As Object
Dim strto, strcc, strsub, strbody As String
Dim sh As Worksheet
Dim signature As String
Dim msg As String
Dim Phone As String
Dim Warehouse As Range
Dim WH As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set sh = Sheets("Master Orders")
For i = 2 To Range("C50000").End(xlUp).Row
If Cells(i, 21) = "Yes" Then
Select Case Time
Case Is < TimeValue("12:00")
msg = "Good morning " & Cells(i, 5)
Case Is < TimeValue("16:00")
msg = "Good afternoon " & Cells(i, 5)
Case Else
msg = "Good evening " & Cells(i, 5)
End Select
For Each Warehouse In Worksheets("Customer Data").Cells(i, 72)
If Warehouse = "Dartmouth" Then WH = Worksheets("Codes").Range("P1:V1").Value
If Warehouse = "Delta" Then WH = Worksheets("Codes").Range("P2:V2").Value
If Warehouse = "Winnipeg" Then WH = Worksheets("Codes").Range("P3:V3").Value
If Warehouse = "Mississauga" Then WH = Worksheets("Codes").Range("P4:V4").Value
If Warehouse = "Laval" Then WH = Worksheets("Codes").Range("P5:V5").Value
Next
Set OutMail = OutApp.CreateItem(0)
strto = Cells(i, 7).Value 'email address
strcc = "kchihani@pods.com"
strsub = "Clear the container at bond - Bonded Warehouse in " & Worksheets("Customer Data").Cells(i, 74) 'email subject
strbody = "<p style='font-family:calibri;font-size:14'>" & msg & "<BR><BR>" & "This message is to inform you that the container has reached the bonded warehouse located:" & "</STYLE></FONT>" & _
"<p style='font-family:calibri;font-size:14;Bold'>" & WH & "</Style></Font><BR>" & "<p style='font-family:New Times Roman;font-size:16'>" & Warehouse & "<BR><BR>" & "</style></font>" & "You may give them a call at " & Phone & ". Please ask for a document called 'cargo control' and take that document, your inventory list and passport to the closest customs office. The customs agent will revise your documents and will ask you to please return the cargo control document back to the bonded facility to complete the process. Once the document is returned and the container is released, we can complete your transport to the final destination storage center. Furthermore, we can move forward with scheduling your remaining moves to your destination address." < BR <> BR > "Thank you" 'email body
With OutMail
.Display
End With
signature = OutMail.HTMLbody
With OutMail
.To = strto
.CC = strcc
.Subject = strsub
.HTMLbody = strbody & vbNewLine & signature
'.send
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
Exit For
Exit For
End If
Next
End Sub
I want it to look in the column on sheet("Customer Data") Column (BV) & find the City name. When the email generates then WH as the range from worksheet("Codes").Range(P:V) based on the city value located on worksheets("codes").Column(S). I ran the code but it does not throw an error & outlook does not generate the email. Any help would be greatly appreciated!
Bookmarks