【发布时间】:2014-02-14 22:06:39
【问题描述】:
我目前想构建一个 VBA 功能,使人们能够使用群组电子邮件地址发送电子邮件(例如,人 A 有一个电子邮件地址 a@111.com,他也是“学生”组的成员,并且可以访问使用群组电子邮件地址 student@111.com 发送电子邮件)
我正在考虑使用 VBA 来构建这样的功能。构造正文、收件人等很容易,但是如何将发件人(即从字段)转移到组电子邮件地址?
【问题讨论】:
我目前想构建一个 VBA 功能,使人们能够使用群组电子邮件地址发送电子邮件(例如,人 A 有一个电子邮件地址 a@111.com,他也是“学生”组的成员,并且可以访问使用群组电子邮件地址 student@111.com 发送电子邮件)
我正在考虑使用 VBA 来构建这样的功能。构造正文、收件人等很容易,但是如何将发件人(即从字段)转移到组电子邮件地址?
【问题讨论】:
您想要的不仅仅是如何发送它吗?我对你的问题有点困惑。
Sub Mail_Workbook_1()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
' Change the mail address and subject in the macro before you run it. Or pass variables to it
With OutMail
.To = "tom@google.com" 'You can also set it equal to something like TextBox1.Text or any string variable or item
.CC = ""
.BCC = ""
'Once again for the next two you can pull this from a cell, a textbox, or really anything
.Subject = "This is the Subject line"
.Body = "Hello World!"
.Attachments.Add ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:\test.txt")
' In place of the following statement, you can use ".Display" to
' display the mail.
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
【讨论】:
也许您只需要编辑回复地址,以便将任何回复发送到群组?
使用 Outlook 的方法如下:
'Tools > References ... > check "Microsoft Outlook object library"
Dim outlookApp As Outlook.Application
Dim mailMsg As MailItem
Dim replyToRecipient As Recipient
Set outlookApp = CreateObject("Outlook.Application")
Set mailMsg = outlookApp.CreateItem(olMailItem)
With mailMsg
.To = "abc@111.com"
Set replyToRecipient = .ReplyRecipients.Add("group@111.com") ' group adderss
replyToRecipient.Resolve
If Not replyToRecipient.Resolved Then Err.Raise 9999, , _
replyToRecipient.Address _
& " could not be resolved as a valid e-mail address."
'...
'... edit body etc. here...
'...
.Display
End With
【讨论】: