使用VBA代码在遇到conidition时向outlook发送电子邮件 [英] Use the VBA code to send an email to outlook when meet a conidition
问题描述
嗨
我想使用VBA代码来感知excel的单元格值,如果遇到设定的conidition并将emial发送给接收者。
但我发现如果我们在单元格中键入值以符合conifiton且结果运行正常,我们可以收到电子邮件,
通过公式或其他方式来更改价值,我们无法收到电子邮件。
belvo的VBA代码。
****************************************** **************
Private Sub Worksheet_Change (ByVal目标作为范围)
如果Target.Address<> " $ B $ 1"然后退出Sub
' 因为 B1 是公式,所以检测 A1
< span style ="color:black; font-family:Calibri; font-size:11pt"> If Range(" $ D $ 1")<> 2然后退出Sub
Dim olApp,Mymail
设置olApp = CreateObject(" Outlook.Application")
设置Mymail = olApp.createitem(0)
使用Mymail
.to =" cary1121@163.com"
' 自己修改
。Subject = Range(" c1")。Value
。Body = Range(" c1" ;)。值
。保存
。send
End With With
End Sub
*************************************** *****************
Hi Anson2018
Wh at是你的意思是"如果我们通过公式或其他来改变价值,我们就无法收到电子邮件。"
根据我的测试,邮件逻辑是正常的。我们需要修改的是条件。以下代码错误或没有意义。
如果Target.Address<> "
乙
1"然后退出Sub
If Range("
Hi
i want to used the VBA code to sense cell value of excel, if there is meet a set conidition and will send a emial to receiver.
but i found a diffcult that if we manualy type value in cell to meet conifiton and the result run is normal,we can get the email,
if we accross formula or other to change the value, we can't get the email.
the belwo the VBA code of excell.
********************************************************
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$B$1" Then Exit Sub '因为B1是公式,所以检测A1
If Range("$D$1") <> 2 Then Exit Sub
Dim olApp, Mymail
Set olApp = CreateObject("Outlook.Application")
Set Mymail = olApp.createitem(0)
With Mymail
.to = "cary1121@163.com" '自己修改
.Subject = Range("c1").Value
.Body = Range("c1").Value
.Save
.send
End With
End Sub
********************************************************
Hi Anson2018
What is your mean of "if we accross formula or other to change the value, we can't get the email."
Based on my test, the mail logic is OK. What is we need to modify is the condition. The following code is wrong or no meaning.
If Target.Address <> "
B
1" Then Exit Sub If Range("
这篇关于使用VBA代码在遇到conidition时向outlook发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!