我希望我的电子表格可以在单元格更改后发送电子邮件。
到目前为止,我有一个宏发送到一组电子邮件和一个命令按钮宏来触发这个,但希望它在单元格改变状态时自动发生。
现在我有:
Sub Create_Email_From_Excel()
Dim SendTo As String
Dim ToMSg As String
For i = 1 To 10
SendTo = ThisWorkbook.Sheets(1).Cells(i, 1)
If SendTo <> “” Then
ToMSg = ThisWorkbook.Sheets(1).Cells(i, 3)
Send_Mail_From_Excel SendTo, ToMSg
End If
Next i
End Sub
Sub Send_Mail_From_Excel(SendTo As String, ToMSg As String)
Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
With OutlookMail
.To = SendTo
.CC = "john@interwebs.com"
.BCC = “”
.Subject = "You have mail"
.Body = "this is your mail"
.Send
End With
和...
Private Sub CommandButton1_Click
Create_Email_From_Excel
End Sub
我不确定从哪里开始,或者我是否朝着正确的方向前进。命令按钮和宏可以正常工作,但我无法继续下去。
如果G列中的单元格从“待处理”更改为“延迟”,那么它可以从excel宏中创建电子邮件,这将是非常好的。
答案 0 :(得分:0)
尝试使用Worksheet_Change事件
实施例
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$1" Then
'
'When someone Edits the cell G1
'
Call Create_Email_From_Excel
'
'
End If
End Sub