我需要Excel VBA代码,以便每当我关闭并更新Excel文件(文件中的数据必须已更新)时,将Skype消息或电子邮件发送给其他人,说明该文件已更新。
我正在寻找可以实现此目标的VBA代码。
重要提示:该代码适用于Skype或Mozilla Thunderbird。
答案 0 :(得分:0)
Here是一篇很好的文章,其中包含有关VBA代码的信息,其中介绍了如何在特定的Excel工作表更新时发送电子邮件。
这是正在使用的代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim nConfirmation As Integer
Dim objNewWorkbook As Excel.Workbook
Dim objNewWorksheet As Excel.Worksheet
Dim objOutlookApp As Object
Dim objMail As Object
nConfirmation = MsgBox("Do you want to send an email notification about the sheet updating now?", vbInformation + vbYesNo, "Mail Sheet Updates")
If nConfirmation = vbYes Then
ActiveWorkbook.Save
On Error Resume Next
Set objOutlookApp = CreateObject("Outlook.Application")
Set objMail = objOutlookApp.CreateItem(olMailItem)
'Change the email details as per your needs
With objMail
.To = "test@datanumen.com"
.Subject = "Email Notifying Sheet Updates"
.Body = "Hi," & vbCrLf & vbCrLf & "The worksheet " & Chr(34) & ActiveWorkbook.Sheets(1).Name & Chr(34) & " in this Excel workbook attachment is updated."
'Attach this workbook
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
End If
End Sub
它可以作为起点。