Word邮件合并批量发送带附件的邮件


标签:
word技巧邮件合并office效率之源教育 |
分类: 工具 |
VBA代码
执行代码前,需要在VBA编辑器中添加对Outlook的引用。
步骤:在VBA编辑器的“工具”菜单中,选择“引用”,并勾选类似于“Microsoft Outlook ##.0 Object Library”的引用,其中“##”是Outlook的版本号(2007是12.0,2010是14.0,2013是15.0)。
Sub emailmergewithattachment
Dim Source As Document, Maillist As Document, TempDoc As
Document
Dim Datarange As Range
Dim i As Long, j As Long
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim mysubject As String, message As String, title As String
Set Source = ActiveDocument
' Check if Outlook is running.
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
End If
' Open the catalog mailmerge document
With Dialogs(wdDialogFileOpen)
End With
Set Maillist = ActiveDocument
' Show an input box asking the user for the subject to be inserted
into the email messages
message = "Enter the subject to be used for each email
message."
title = " Email Subject
Input"
' Display message, title
mysubject = InputBox(message, title)
' Iterate through the Sections of the Source document and the rows
of the catalog mailmerge document,
' extracting the information to be included in each email.
For j = 1 To Source.Sections.Count - 1
Next j
Maillist.Close wdDoNotSaveChanges
'
If bStarted Then
End If
MsgBox Source.Sections.Count - 1 & " messages have
been sent."
'Clean up
Set oOutlookApp = Nothing
End Sub
使用方法:
【OFFICE知识库】