【发布时间】:2015-04-14 15:53:24
【问题描述】:
好的,那么,任何人都知道是否可以在每次更新 excel 表时自动从 excel 向 Outlook 发送电子邮件提醒?如果是这样,宏的那部分会是什么样子?我在任何地方都无法在网上找到它。
【问题讨论】:
好的,那么,任何人都知道是否可以在每次更新 excel 表时自动从 excel 向 Outlook 发送电子邮件提醒?如果是这样,宏的那部分会是什么样子?我在任何地方都无法在网上找到它。
【问题讨论】:
以下代码似乎有效。 右键单击工作表并选择“查看代码” 并为工作表选择更改事件。
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
【讨论】: