我在让 Outlook 通过 Excel 电子表格发送电子邮件时遇到问题。当我将 Outlook 2013 与 Gmail 一起使用时没有问题,但是当我使用具有唯一域 (someEmail@CreatedDomain.mil) 的早期版本 (2010) 时出现错误。我想说它是因为域名,但我不确定。下面是我在网上找到的代码。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
'-----AUTOMATIC EMAIL GENERATION-----------------------
Dim answer As String
answer = MsgBox("Saving this document will send an email to the database director and close the database. Are you sure you want to save?", _
vbYesNo, "Save confirmation")
' Above code informs the user
' that an automated email will be sent to the database
' director and prompts them if they are ready to save
'Code uses the users answer to either carryout the generated email process or to not save the changes.
If answer = vbNo Then Cancel = True
If Cancel = True Then Exit Sub
If answer = vbYes Then
'Connects to outlook and retrieves information needed to create and send the email.
Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)
'Contains the email address of the person receiving the email.
newmsg.Recipients.Add ("roman.hope.ctr@navy.mil")
newmsg.Subject = "Automated email from excel database" 'Sets the automated subject line to the email
newmsg.Body = "There has been a change to the excel database from the person sending linked to this email."
'Above code has the body of the automated email
'sets the email to "display" in the background then sends it in the next line of code (all in the background).
newmsg.Display
newmsg.Send 'sends the email
'Displays a confirmation that the email has been sent.
MsgBox "The email has been successfully sent", , "Email confirmation"
' ActiveWorkbook.Save
End If
End Sub ' End of function
最佳答案
我已经找到了问题所在,这与代码无关,而与我所在的网络有关。
该网络具有自动电子邮件保护功能,可阻止所有应用程序发送自动通用电子邮件。
谢谢大家的帮助。
关于vba - 更改电子表格时使用 Outlook 从 Excel 发送自动电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31319378/