Excel更新时Excel的电子邮件提醒

时间:2015-04-14 06:43:48

标签: excel vba excel-vba

好的,有人知道每次excel表更新时是否可以自动从excel向outlook发送电子邮件提醒?如果是这样,宏的那部分会是什么样子?我无法在任何地方找到它。

1 个答案:

答案 0 :(得分:0)

以下代码似乎有效。   右键单击工作表,然后选择“查看代码”'   并选择工作表的更改事件。

Private Sub Worksheet_Change(ByVal Target As Range)
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "Hi there" & vbNewLine & vbNewLine & _
          "This is line 1" & vbNewLine & _
          "This is line 2" & vbNewLine & _
          "This is line 3" & vbNewLine & _
          "This is line 4"

On Error Resume Next
With OutMail
    .To = "someone@someemail.com"
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .Body = strbody
    'You can add a file like this
    '.Attachments.Add ("C:\test.txt")
    .Send   'or use .Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub