在excel单元格更改时运行我的macros

我希望有一个单元格更改后,我的电子表格发送电子邮件。

到目前为止,我有一个macros发送到一组电子邮件和一个命令buttonmacros触发这个,但希望它自动发生时,一个单元格更改状态。

我现在有:

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 

我不确定该从哪里出发,或者如果我要走向正确的方向。 命令button和macros工作,但我不知所措。

如果G列中的某个单元格从“挂起”更改为“迟到”,这可能会超出从Excelmacros创build的电子邮件。

尝试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