logo资料库

用VBA操纵Lotus_notes邮件全集.doc

第1页 / 共68页
第2页 / 共68页
第3页 / 共68页
第4页 / 共68页
第5页 / 共68页
第6页 / 共68页
第7页 / 共68页
第8页 / 共68页
资料共68页,剩余部分请下载后查看
287 , 用 lotus notes 发送邮件, 第一种方法, Sub SendWithLotus() Dim noSession As Object, noDatabase As Object Dim noDocument As Object, noAttachment As Object Dim FileSelf As String Dim i As Long Const EMBED_ATTACHMENT = 1454 Const stSubject As String = "For Lotus VBA Programming Test only" Dim stMsg As String FileSelf = ThisWorkbook.Path + "\" + ThisWorkbook.Name stMsg = "Bst & Rgds" & vbCrLf & _ Application.UserName & vbCrLf & _ vbCrLf & _ "**************************************************************************" & vbCrLf & _ "(This's an automated e-mail notification, please do not reply this message.)" Dim vaRecipient As Variant vaRecipient = VBA.Array("huangfeng8211@163.com") 'Insert Lotus Notes COM object. Set noSession = CreateObject("Notes.NotesSession") Set noDatabase = noSession.GETDATABASE("", "D:\notes\data\mail3\tonyhf.nsf") If noDatabase.IsOpen = False Then noDatabase.OPENMAIL Set noDocument = noDatabase.CREATEDOCUMENT Set noAttachment = noDocument.CREATERICHTEXTITEM("Body") noAttachment.EMBEDOBJECT EMBED_ATTACHMENT, "", FileSelf With noDocument .Form = "Memo" .SendTo = vaRecipient .Subject = stSubject .Body = stMsg .SAVEMESSAGEONSEND = True .PostedDate = Now() .SEND 0, vaRecipient End With Set noDocument = Nothing Set noDatabase = Nothing Set noSession = Nothing AppActivate "Microsoft Excel" MsgBox "This file be sent", vbInformation
End Sub 第二种方法 Sub SendWithLotus() Dim noSession As Object, noDatabase As Object Dim noDocument As Object, noAttachment As Object Dim vaFiles As Variant Dim i As Long Const EMBED_ATTACHMENT = 1454 Const stSubject As String = "For Lotus VBA Programming Test only" Const stMsg As String = "This file is for you! just for reference" & vbCrLf & "I am StanleyPan" Dim vaRecipient As Variant vaRecipient = VBA.Array("stanleypan2000@hotmail.com", "stanley.pan@IsolaAg.com") vaFiles = Application.GetOpenFilename(FileFilter:="Excel Filer (*.xls),*.xls", Title:="Attach files for outgoing E_Mail", MultiSelect:=True) If Not IsArray(vaFiles) Then Exit Sub 'Insert Lotus Notes COM object. Set noSession = CreateObject("Notes.NotesSession") Set noDatabase = noSession.GETDATABASE("", "D:\notes\data\mail3\tonyhf.nsf") If noDatabase.IsOpen = False Then noDatabase.OPENMAIL Set noDocument = noDatabase.CREATEDOCUMENT Set noAttachment = noDocument.CREATERICHTEXTITEM("Body") With noAttachment For i = 1 To UBound(vaFiles) .EMBEDOBJECT EMBED_ATTACHMENT, "", vaFiles(i) Next i End With With noDocument .Form = "Memo" .SendTo = vaRecipient .Subject = stSubject .Body = stMsg .SAVEMESSAGEONSEND = True .PostedDate = Now() .SEND 0, vaRecipient End With Set noDocument = Nothing Set noDatabase = Nothing Set noSession = Nothing AppActivate "Microsoft Excel" MsgBox "This file is send OK", vbInformation End Sub
1, 返回当前数据库的信息, a, 返回当前数据库的名称, 结果, b, 返回当前数据库的文件名, c, 返回当前数据库的文件路径, 2,发送邮件的一些设置,
Sub aaaaaa() Dim no As Object Dim db As Object Dim doc As Object Dim fields As Object Dim nofields As Object Dim att As Variant att = Application.GetOpenFilename(FileFilter:="Excel Filer (*.xls),*.xls", _ Title:="Attach files for outgoing E_Mail", MultiSelect:=True) '添加附件 Set no = CreateObject("notes.notessession") '建立和邮件的连接 Set db = no.CURRENTDATABASE '建立和邮件数据库的连接 Set doc = db.CREATEDOCUMENT '创建一个新的邮件 Set fields = doc.CREATERICHTEXTITEM("body") '设置新邮件的正文(附件)对象 With fields '设置邮件的正文和附件 .APPENDTEXT " this e-mail is generated by an automated process just for a test" .ADDNEWLINE 1 '增加第一行
.APPENDTEXT " please do not reply." .ADDNEWLINE 2 '增加第二行 For i = 1 To UBound(att) '添加附件 .EMBEDOBJECT 1454, "", att(i) Next i End With With doc '设置新邮件的除正文和附件外的其他信息 .form = "Memo" '新邮件 .sendto = VBA.Array("huangfeng8211@163.com", "tonyhf@cn.ibm.com") '发送给 .Subject = "this mail is just for testing" '主题 .SAVEMESSAGEONSEND = True '是否保存发送的邮件到发件箱 .postdate = DateAdd("d", 1, Date) '发送日期等于当天 .SEND 0 '发送 End With MsgBox "successfully sent out the mail!" Set no = Nothing '释放内存 Set db = Nothing Set doc = Nothing Set fields = Nothing End Sub 在添加附件的时候,如果只是想将当前的活动工作薄作为附件的话,如下, 注意一下, 如果是 1452 的话, 效果如下,
会出现一个提示, 询问文档包含外部对象链接, 是否要更新链接, 如果确定的话, 效果如下, 会将 EXCEL 文件中的内容以图片形式打开, 同时文件是只读格式的, 如果是 1453, 效果如下, 不会有提示, 但是文件为只读,
如果为 1454, 则为正常的 EXCEL 文件格式, 3, 提取邮件的一些信息, 以上的发件人,发送时间,主题等信息还可以如下表示,
运行结果, 4,指定是在收件箱,发件箱或其他自定义的文件夹, a, 收件箱等邮箱本身就存在的, b, 如果是自己创建的文件夹及子文件夹, 比如在我的邮箱中有自定义的文件夹,folders, 如果要想获取其下面的子文件夹之一的相关资料,则应如下书写, 4, 用上面的方法提取出来的发件人是有公司名称的, anotes.CREATENAME(adocument.GETITEMVALUE("from")(0)).ABBREVIATED 如果不使用 abbreviated, 则结果为,
分享到:
收藏