То, что я ищу, это когда: ячейка ("D"). Значение = "4. Подтверждено" Затем "Текст", но также ниже в теле письма, если .Value = "4. Подтверждено" это добавит дополнительное предложение.
Sub Email_From_Excel_Basic()
' This identifies what means what
Dim emailApplication As Object
Dim emailItem As Object
Dim mymsg As String
Dim cell As Range
Application.ScreenUpdating = False
Set emailApplication = CreateObject("Outlook.Application")
' Now we build the email.
On Error GoTo cleanup
For Each cell In Worksheets("owvr").Columns("S").Cells
Set emailItem = emailApplication.CreateItem(0)
If cell.Value Like "?*@?*.?*" And _
Cells(cell.Row, "T") = "Yes" Then
With emailItem
' This is who the email is being sent to
.To = Cells(cell.Row, "S").Value
.CC = Cells(cell.Row, "S").Value
' This is the subject of the email
.Subject = "Status update"
' This is the body of the email based on cell references
mymsg = "Dear " & Cells(cell.Row, "A").Value & " team," & vbNewLine & vbNewLine
Dim sts As String
If Cells(cell.Row, 4).Value = "1. New Order" Then
sts = "Your order has been received and will be processed."
ElseIf Cells(cell.Row, 4).Value = "2. Shipped" Then
sts = "Your order has been shipped"
ElseIf cell("D").Value = "3. In-Process" Then
sts = "Your order has been received. We are waiting on information to confirm your order."
ElseIf cell("D").Value = "4. Confirmed" Then
sts = "Your order has been confirmed. We will approve your order to ship as all requirements are fulfilled."
ElseIf cell("D").Value = "5. Approved" Then
sts = "Your order is approved to ship."
Else
End If
'Then we continue into the rest of the body
mymsg = mymsg & "Status: " & stts & vbNewLine
mymsg = mymsg & "number: " & Cells(cell.Row, "I").Value & vbNewLine
mymsg = mymsg & "type: " & Cells(cell.Row, "C").Value & vbNewLine
mymsg = mymsg & "number: " & Cells(cell.Row, "B").Value & vbNewLine
mymsg = mymsg & "Incoterms: " & Cells(cell.Row, "P").Value & vbNewLine
mymsg = mymsg & "EXW: " & Cells(cell.Row, "E").Value & vbNewLine
mymsg = mymsg & "delivery: " & Cells(cell.Row, "H").Value & vbNewLine & vbNewLine
Проблема возникает здесь, с тем, что у меня есть, она не будет отправлять электронное письмо, если Значение = "4. Подтверждено". Но он отправит другие.
If Cells(cell.Row, 4).Value = "4. Confirmed" Then
sts = "Deposit invoice: " & Cells(cell.Row, "K").Value & vbNewLine & "Additional invoice: " & Cells(cell.Row, "M").Value & vbNewLine & "Insurance certificate: " & Cells(cell.Row, "J").Value & vbNewLine & "Broker/Freight forwarder information: " & Cells(cell.Row, "L").Value & vbNewLine
Else
End If
mymsg = mymsg & "For further details please use the contact information below:" & vbNewLine & vbNewLine
mymsg = mymsg & "Best regards" & vbNewLine & vbNewLine
.Body = mymsg
.Send
End With
Set emailItem = Nothing
End If
Next cell
cleanup:
Set emailApplication = Nothing
Application.ScreenUpdating = True
End Sub