我有一个Excel VBA(Send_Mail)通过Lotus Notes发送电子邮件。它工作正常,但我需要一次性向多个人发送单独的电子邮件。
在我的Excel工作表中。单元格A7向下将是电子邮件地址,可以上升到200+行,B7的主题为Line,单元格C7的正文为email。(所有这些都是用不同的宏自动填充的)。然而,我的代码(Send_Mail)只是向单元格A7中的地址发送一封电子邮件。我需要发送邮件到所有的电子邮件地址是在栏A7向前与其各自的主题(栏B)和邮件正文(栏C)。
下面是我的代码:
Public TOID As String
Public CCID As String
Public SECT As String
Public ACCO As String
Public SUBJ As String
Sub Send_Mail()
Dim answer As Integer
answer = MsgBox("DO YOU HAVE LOTUS NOTES OPEN ?? Not WebLotus notes", vbYesNo + vbQuestion, "LOTUS NOTES")
If answer = vbNo Then
MsgBox "Please Open Notes and Try the Macro Again"
Exit Sub
Else
End If
Application.DisplayAlerts = False
Call Send
MsgBox "Mail Sent to " & (Range("L2").Value) & " " & "Recipents"
Application.DisplayAlerts = True
End Sub
Public Function Send()
SendEMail = True
Sheets("Main").Select
TOID = Range("A7").Value
CCID = ""
SUBJ = Range("B7").Value
'On Error GoTo ErrorMsg
Dim EmailList As Variant
Dim ws, uidoc, Session, db, uidb, NotesAttach, NotesDoc, objShell As Object
Dim RichTextBody, RichTextAttachment As Object
Dim server, mailfile, user, usersig As String
Dim SubjectTxt, MsgTxt As String
Set Session = CreateObject("Notes.NotesSession")
user = Session.UserName
usersig = Session.COMMONUSERNAME
mailfile = Session.GETENVIRONMENTSTRING("MailFile", True)
server = Session.GETENVIRONMENTSTRING("MailServer", True)
Set db = Session.GETDATABASE(server, mailfile)
If Not db.IsOpen Then
Call db.Open("", "")
Exit Function
End If
Set NotesDoc = db.CREATEDOCUMENT
With NotesDoc
.Form = "Memo"
.Subject = SUBJ 'The subject line in the email
.Principal = user
.sendto = TOID 'e-mail ID variable to identify whom email need to be sent
.CopyTo = CCID
End With
Set RichTextBody = NotesDoc.CREATERICHTEXTITEM("Body")
With NotesDoc
.COMPUTEWITHFORM False, False
End With
'==Now set the front end stuff
Set ws = CreateObject("Notes.NotesUIWorkspace")
If Not ws Is Nothing Then
Set uidoc = ws.EDITDOCUMENT(True, NotesDoc)
If Not uidoc Is Nothing Then
If uidoc.EDITMODE Then
'Mail Body
Sheets("Main").Select
Range("C7").Select
Dim rnBody1 As Range
Set rnBody1 = Selection
rnBody1.CopyPicture
'rnBody1.Copy
Call uidoc.GOTOFIELD("Body")
Call uidoc.Paste
End If
End If
End If
Call uidoc.Send
Call uidoc.Close
'close connection to free memory
Set Session = Nothing
Set db = Nothing
Set NotesAttach = Nothing
Set NotesDoc = Nothing
Set uidoc = Nothing
Set ws = Nothing
Sheets("Main").Select
End Function
2条答案
按热度按时间u91tlkcl1#
我担心太多的新细节会让你感到困惑,我必须承认我还没有测试过下面的代码,所以请不要认为这会彻底解决你的问题。
下面给你一个想法,你可能会使用一个循环作为你的要求。也见例子here,其中包括的情况下,你可能需要批量发送(无可否认的链接是为Outlook),也是一个例子,使用循环。
我已经在代码中包含了一些解释。没有更多的信息很难适当地定制这一点,但我希望它能有所帮助。
sqxo8psd2#
你也许该考虑一下。
宏将遍历“Sheet1”中的每一行,如果B列中有电子邮件地址,C:Z列中有文件名,则宏将使用此信息创建邮件并发送。
查看此链接了解所有详细信息。
https://www.rondebruin.nl/win/s1/outlook/amail6.htm