现在,我有一本带有一些VBA的工作簿,当按下按钮时,该工作簿将向一个用户发送电子邮件(电子邮件地址已进行硬编码)。效果很好。但是,我想知道是否可以“抄送”电子邮件给正在按按钮发送电子邮件的用户。可能来自10-15个不同的人。
现在,下面的代码将通过电子邮件将“表”的副本“ [email protected]”发送到“ [email protected]”,并且在收件箱中它来自正确的用户。它以某种方式能够利用用户的电子邮件并自动为他们发送邮件,因此我认为也必须有一种让他们自己抄送自己的方法。
所有电子邮件帐户都将在Microsoft Oulook上。
这是向一个人发送电子邮件的代码(我从http://www.rondebruin.nl/win/s1/outlook/amail2.htm获得):
'Sub that emails the 3rd sheet in the body of an email
Sub Mail_Sheet_Outlook_Body()
Call UnProtect
Application.ReferenceStyle = xlA1
'RangetoHTML function is copied in the module after this sub.
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set rng = Nothing
Set rng = Sheets("Print").UsedRange
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "New Order from Employee"
.HTMLBody = RangetoHTML(rng)
.Send 'or use .Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
Call Protect
End Sub
因此,重申一下我要问的是,无论如何,当[email protected]发送订单/发送电子邮件时,它会“抄送”给自己,而当[email protected]做同样的事情时只有抄送自己。根据谁的帐户打开了工作簿动态更改。
尝试使用application.Session.CurrentUser.Address获取电子邮件ID
Sub EmailWithCCTome()
Dim outlookobj As Object
Dim emailitem As Object
Set outlookobj = CreateObject("Outlook.Application")
Set emailitem = outlookobj.CreateItem(olMailItem)
With emailitem
.To = toemail
.CC = outlookobj.Session.CurrentUser.Address
End With
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句