|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
求助批量发送邮件问题。
用版主提供的程序想根据复选框选出的邮件地址发送后面对应的邮件,出现了两个问题
一个是复选框错位,选中第一行,结果值赋的是第二行的邮件地址
第二个运行到 .EmbedObject EMBED_ATTACHMENT, "", vaFiles(I)
时提示you must provide a file path 究竟什么原因?
我是vba菜鸟,只能用现有程序改改用用,请帮帮我实现这个功能,谢谢!
Sub SendWithLotus()
Const EMBED_ATTACHMENT = 1454
Const stSubject As String = "For Lotus VBA Programming Test only"
Dim noSession As Object, noDatabase As Object
Dim noDocument As Object, noAttachment As Object
Dim I%, stMsg$, FileSelf$
Dim vaRecipient() As String
Dim sh As Shape
stMsg = "内容" & vbCrLf & _
Application.UserName
I = 0
ReDim vaRecipient(ActiveSheet.Shapes.Count - 1) As String
ReDim vaFiles(ActiveSheet.Shapes.Count - 1) As String
For Each sh In ActiveSheet.Shapes
If sh.Type = msoFormControl Then
If sh.FormControlType = xlCheckBox Then
If sh.ControlFormat.Value = 1 Then
vaRecipient(I) = sh.BottomRightCell.Offset(0, 1)
'add by fy
MsgBox vaRecipient(I), vbInformation
vaFiles(I) = sh.BottomRightCell.Offset(0, 2)
MsgBox vaFiles(I), vbInformation
'add end
I = I + 1
End If
End If
End If
Next
If I = 0 Then MsgBox "No Names found to send mail to.": Exit Sub
ReDim Preserve vaRecipient(I - 1) As String
'del by fy
'vaFiles = Application.GetOpenFilename(FileFilter:="File Filer (*.*),*.*", Title:="Attach files for outgoing E_Mail ", MultiSelect:=True)
'If Not IsArray(vaFiles) Then Exit Sub
'del end
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
Set noDocument = noDatabase.CreateDocument
Set noAttachment = noDocument.CreateRichTextItem("Body1")
'modi by fy
'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
'modi end
For I = 1 To UBound(vaFiles)
With noAttachment
.EmbedObject EMBED_ATTACHMENT, "", vaFiles(I)
End With
With noDocument
.Form = "Memo"
.sendto = vaRecipient
.Subject = stSubject
.Body = stMsg
.SaveMessageOnSend = True
.PostedDate = Now()
.Send 0, vaRecipient()
End With
Next I
'modi end
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
AppActivate "Microsoft Excel"
MsgBox "This file be sent", vbInformation
End Sub |
|