ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 13974|回复: 13

[求助] 用excel通过lotus notes自动发送邮件,如何能发送给多位copy to

[复制链接]

TA的精华主题

TA的得分主题

发表于 2011-8-19 10:48 | 显示全部楼层 |阅读模式
本帖已被收录到知识树中,索引项:邮件应用开发
各位大虾,

我有一个以前高手留下的excel VBA文件,可以自由选择文件夹路径,添加附件,选择需要发送的email address,copy to 的email address.平时用的都很好。唯一的遗憾是目前在 copy to的column里面只能放一个地址,如果放两个,即使中间用了;分割,也只有第一个人可以收到。

能用数组的方式吗?

如何更改?

Copy of Send mails to suppliers V2.1.zip (36.09 KB, 下载次数: 444)


TA的精华主题

TA的得分主题

 楼主| 发表于 2011-8-19 11:50 | 显示全部楼层
Sub Send_Mail()

Dim Recipient(100) As Variant
Dim CopyToRecipient(100) As Variant
Dim Attachment(100) As Variant
Dim Subject(100) As Variant
Dim BodyText(100) As Variant
Dim recipient_address As String

Dim SaveIt As Boolean

column_signature = 6
row_signature = 2

ligne_standard_message = 2
column_standard_message = 7

column_standard_subject = 5
row_standard_subject = 2

column_supplier = 1
column_to = 2
column_key_contact = 3
column_copy_to = 4
column_file_name = 5
column_subject = 6
column_body_text = 7
column_check = 8
column_path = 9

'On désactive la maj de l'écran, les messages d'alertes et les macro evenementielles
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False

SaveIt = True
Sheets("datas").Activate
n = 1
Do While Not IsEmpty(Cells(n, column_file_name))
n = n + 1
Loop
n = n - 1

index_mail = -1
        'Recipient
        For i = 2 To n
          If Cells(i, column_to).Text <> "" And Cells(i, column_key_contact).Text <> "" Then
          index_mail = index_mail + 1
          Recipient(index_mail) = Cells(i, column_to).Text
          Cells(i, column_check).Value = "ok"
          mails_to_send = mails_to_send + 1
          Else
          Cells(i, column_check).Value = "not ok"
          End If
        Next
        
  last_index = index_mail
        
        'Copy to
        index_mail = 0
        For i = 2 To n
          If Cells(i, column_check).Value = "ok" Then
          CopyToRecipient(index_mail) = Cells(i, column_copy_to).Text
          index_mail = index_mail + 1
          End If
        Next
  
        Dim Maildb As Object 'The mail database
        Dim UserName As String 'The current users notes name
        Dim MailDbName As String 'THe current users notes mail databasename
        Dim MailDoc As Object 'The mail document itself
        Dim AttachME As Object 'The attachment richtextfile object
        Dim Session As Object 'The notes session
        Dim EmbedObj As Object 'The embedded object (Attachment)
        
        'Body of the message
        index_mail = 0
        For i = 2 To n
          If Cells(i, column_check).Value = "ok" Then
          BodyText(index_mail) = Cells(i, column_body_text).Text
          index_mail = index_mail + 1
          End If
        Next
        
        
        'Subject
        index_mail = 0
        For i = 2 To n
          If Cells(i, column_check).Value = "ok" Then
          Subject(index_mail) = Cells(i, column_subject).Text
          index_mail = index_mail + 1
          End If
        Next
        
        'Attachment
        index_mail = 0
        For i = 2 To n
          If Cells(i, column_check).Value = "ok" Then
          Attachment(index_mail) = Cells(i, column_path).Text
          index_mail = index_mail + 1
          End If
        Next
    For index_mail = 0 To last_index
    recipient_address = Recipient(index_mail)
    copy_to_address = CopyToRecipient(index_mail)
        'Start a session to notes
        Set Session = CreateObject("Notes.NotesSession")
        
        'Get the sessions username and then calculate the mail file name
        'You may or may not need this as for MailDBname with some systems you
        'can pass an empty string
        UserName = Session.UserName
        MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
        'Open the mail database in notes
        Set Maildb = Session.GETDATABASE("", MailDbName)
         If Maildb.IsOpen = True Then
                    'Already open for mail
         Else
                 Maildb.OPENMAIL
         End If
   
        'Set up the new mail document
        Set MailDoc = Maildb.CREATEDOCUMENT
        MailDoc.Form = "Memo"
        MailDoc.sendto = recipient_address
        MailDoc.copyto = copy_to_address
        MailDoc.Subject = Subject(index_mail)
        MailDoc.body = BodyText(index_mail)
        'MailDoc.ReturnReceipt = "1"
        
        MailDoc.SAVEMESSAGEONSEND = SaveIt

        'Les trois attachement sont les noms et chemins des fichiers à envoyer
        If Attachment(index_mail) <> "" Then
                Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment(" & index_mail & " )")
                Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment(index_mail), "Attachment(" & index_mail & " )")
                'MailDoc.CREATERICHTEXTITEM ("Attachment(" & i & " )")
        End If
        

         'Send the document
         MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
         MailDoc.SEND 0, recipient_address
         
         
        'Clean Up
        Set Maildb = Nothing
        Set MailDoc = Nothing
        Set AttachME = Nothing
        Set Session = Nothing
        Set EmbedObj = Nothing
    Next
        
    Sheets("Datas").Select
    Cells.Select
    Selection.RowHeight = 15
    Cells.Select
    Cells.EntireColumn.AutoFit

'Reactivation des messages d'alerte et des macros evenementielles
Application.EnableEvents = True
Application.DisplayAlerts = True

        
End Sub

把这段copy出来方便大家看,我个人觉得问是 “copy to"的那里能不能用数组的方式得到多个值,可是不知道具体怎么做?

TA的精华主题

TA的得分主题

发表于 2011-12-22 00:53 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
catstory 发表于 2011-8-19 11:50
Sub Send_Mail()

Dim Recipient(100) As Variant

copy_to_address

用逗号将地址分割,放到这个串里面不行吗?

TA的精华主题

TA的得分主题

发表于 2011-12-21 23:54 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
好复杂,关注学习中

TA的精华主题

TA的得分主题

发表于 2012-3-9 23:36 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
Mark it . Thanks you for your codes.

TA的精华主题

TA的得分主题

发表于 2012-10-31 09:21 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-8-1 10:09 | 显示全部楼层
Mark it                                      

TA的精华主题

TA的得分主题

发表于 2014-7-8 19:14 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2014-7-8 20:52 | 显示全部楼层
这样就可以了,

vaRecipient = VBA.Array("邮件1", "邮件2")

TA的精华主题

TA的得分主题

发表于 2014-7-8 20:54 | 显示全部楼层
lyh512250428 发表于 2014-7-8 19:14
怎么 发送前弹出mail  窗体 二次确认?

在send之前自己用msgbox写一段控制代码就是了,
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-3-29 14:46 , Processed in 0.051670 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表