保存工作簿时发送电子邮件 [英] Send an email when workbook is saved

查看:171
本文介绍了保存工作簿时发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送一封电子邮件,将电子表格的更改用户更新。我试图使这样做,以便当文档保存时,将会有一个电子邮件自动发送,并带有更改列表。

I am trying to send an email that will update users of changes to a spread sheet. I am trying to make it so that when the document is saved there will be an email automatically sent with a list of the changes.

有没有人知道在保存文档时是否可以自动化电子邮件?

Does anyone know if it is possible to automate email upon saving the document?

推荐答案

您可以将这段代码用于Chip Pearson而不是很容易理解,这种方法也依赖于使用outlook:

You can use this code here not fancy as Chip Pearson but easy to understand, This method also relies on using outlook:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim Outlook As Object, EMail As Object

Set Outlook = CreateObject("Outlook.Application")

Set EMail = Outlook.CreateItem(0)

With EMail
    .To = "EmailAddress1@Server.com; Email2@aol.com"
    .CC = ""
    .BCC = ""
    .Subject = "Put your subject here"
    .Body = "Add you E-Mail Message Here"
    .Attachments.Add ActiveWorkbook.FullName ' To add active Workbook as attachment
    .Attachments.Add "C:\Test.xlsx" ' To add other files just use path, Excel files, pictures, documents pdf's ect.
    .Display   'or use .Send to skip preview
End With


Set EMail = Nothing

Set Outlook = Nothing

End Sub

设置此项以下是完整指南:

To set this up Here is the full guide:

首先使用 ALT + F11 打开VBA窗口,然后选择Worbook在右边的窗口中,然后从下拉菜单中下载:

First open up the VBA window using ALT + F11 then Select Worbook on the window to the right, Then workbook from the drop down:

然后从右下角选择BeforeSave:

Then from the Drop down on the right Select BeforeSave:

然后粘贴您的代码:

您应该以此结尾:

这篇关于保存工作簿时发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆