ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If statement to send email (https://www.excelbanter.com/excel-programming/301228-if-statement-send-email.html)

Michael McClellan

If statement to send email
 
Want to give this one a try?

Why does all email get sent to and never to


If (Range("A7").Value = "D") Then
.To = "
Else
.To = "
End If
.CC = ""
.BCC = ""
.Subject = "ORDER ENTERED: " & CurrDir
.Body = "Hi there. Your order: " & CurrDir & " has been
entered." & vbNewLine & _
"This is an automatically generated message. GET
MORE ORDERS!"
'.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With

Ron de Bruin

If statement to send email
 
Use this

Dim StrTo As String
If Sheets("Sheet1").Range("A7").Value = "D" Then
StrTo = "
Else
StrTo = "
End If

and this in the to line
..To = StrTo


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Michael McClellan" wrote in message om...
Want to give this one a try?

Why does all email get sent to and never to


If (Range("A7").Value = "D") Then
.To = "
Else
.To = "
End If
.CC = ""
.BCC = ""
.Subject = "ORDER ENTERED: " & CurrDir
.Body = "Hi there. Your order: " & CurrDir & " has been
entered." & vbNewLine & _
"This is an automatically generated message. GET
MORE ORDERS!"
'.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With




Charles

If statement to send email
 
Michale,

Try,

If (Range("A7").Value = "D") Then
.To = "
Else: <<<<< add
.To = "
End If
.CC = ""
.BCC = ""
.Subject = "ORDER ENTERED: " & CurrDir
.Body = "Hi there. Your order: " & CurrDir & " has been
entered." & vbNewLine & _
"This is an automatically generated message. GET
MORE ORDERS!"
'.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With


HTH

Charle

--
Message posted from http://www.ExcelForum.com


Nigel

If statement to send email
 
Change your logic to

If Range("A7").Value = "D" then

or to be more precise you might want to text for upper case and trim any
spaces from the cell

If Ucase(Trim(Range("A7").Value)) = "D" then

Cheers
Nigel

"Michael McClellan" wrote in message
om...
Want to give this one a try?

Why does all email get sent to and never to


If (Range("A7").Value = "D") Then
.To = "
Else
.To = "
End If
.CC = ""
.BCC = ""
.Subject = "ORDER ENTERED: " & CurrDir
.Body = "Hi there. Your order: " & CurrDir & " has been
entered." & vbNewLine & _
"This is an automatically generated message. GET
MORE ORDERS!"
'.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With





All times are GMT +1. The time now is 10:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com