Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Georgea Georgea is offline
external usenet poster
 
Posts: 28
Default Add CC addresses in Macro Merge

Hello,
I use the macro below to create and send an HTML email merge with
attachments. It references a directory that stores the To email address and
attachment link. I would like to cc 2 other people on each email and hope
someone can help me with the code. If a dialogue box simply asked who should
be cc'd, that would be fine (as long as I can enter multiple addresses).

Thanks very much!

Sub emailmergewithattachments()
'To create the email messages in HTML format
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. If it is not, start Outlook
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
' Open the catalog mailmerge document
With Dialogs(wdDialogFileOpen)
.Show
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."
' Set prompt.
Title = " Email Subject Input"
' Set title.
' 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
source.Sections(j).Range.Copy
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.BodyFormat = olFormatHTML
.Display
Set objDoc = .GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Paste
Set datarange = Maillist.Tables(1).Cell(j, 1).Range
datarange.End = datarange.End - 1
.To = datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set datarange = Maillist.Tables(1).Cell(j, i).Range
datarange.End = datarange.End - 1
.Attachments.Add Trim(datarange.Text), olByValue, 1
Next i
.Send
End With
Set oItem = Nothing
Next j
Maillist.Close wdDoNotSaveChanges
' Close Outlook if it was started by this macro.
If bStarted Then
oOutlookApp.Quit
End If
MsgBox source.Sections.Count & " messages have been sent."
'Clean up
Set oOutlookApp = Nothing
End Sub

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Add CC addresses in Macro Merge

Add the .cc line after the .To = DataRange

.To = DataRange
.cc = ; "

Or, according to the Help on the .cc attribute, it may be better to use the
Recipients object of Outlook

Outlook Developer Reference
Recipients Object
Contains a collection of Recipient objects for an Outlook item.
Remarks


Use the Recipients property to return the Recipients object of an
AppointmentItem, JournalItem, MailItem, MeetingItem, or TaskItem object.

Use the Add method to create a new Recipient object and add it to the
Recipients object. The Type property of a new Recipient object is set to the
default for the associated AppointmentItem, JournalItem, MailItem, or
TaskItem object and must be reset to indicate another recipient type.

Use Recipients(index), where index is the name or index number, to return a
single Recipient object. The name can be a string representing the display
name, the alias, or the full SMTP e-mail address of the recipient.


Example


The following example creates a new MailItem object and adds Jon Grande as
the recipient using the default type ("To").

Visual Basic for Applications
Set myItem = Application.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Add ("Jon Grande")

The following example creates the same MailItem object as the preceding
example, and then changes the type of the Recipient object from the default
("To") to CC.

Visual Basic for Applications
Set myItem = Application.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Add ("Jon Grande")
myRecipient.Type = olCC


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"GeorgeA" wrote in message
...
Hello,
I use the macro below to create and send an HTML email merge with
attachments. It references a directory that stores the To email address
and
attachment link. I would like to cc 2 other people on each email and hope
someone can help me with the code. If a dialogue box simply asked who
should
be cc'd, that would be fine (as long as I can enter multiple addresses).

Thanks very much!

Sub emailmergewithattachments()
'To create the email messages in HTML format
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. If it is not, start Outlook
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
' Open the catalog mailmerge document
With Dialogs(wdDialogFileOpen)
.Show
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."
' Set prompt.
Title = " Email Subject Input"
' Set title.
' 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
source.Sections(j).Range.Copy
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.BodyFormat = olFormatHTML
.Display
Set objDoc = .GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Paste
Set datarange = Maillist.Tables(1).Cell(j, 1).Range
datarange.End = datarange.End - 1
.To = datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set datarange = Maillist.Tables(1).Cell(j, i).Range
datarange.End = datarange.End - 1
.Attachments.Add Trim(datarange.Text), olByValue, 1
Next i
.Send
End With
Set oItem = Nothing
Next j
Maillist.Close wdDoNotSaveChanges
' Close Outlook if it was started by this macro.
If bStarted Then
oOutlookApp.Quit
End If
MsgBox source.Sections.Count & " messages have been sent."
'Clean up
Set oOutlookApp = Nothing
End Sub


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mailmerge won't merge over 25 addresses Robin S Mailmerge 1 January 4th 08 07:10 PM
mail merge addresses disappear jamietron Mailmerge 1 December 18th 06 04:00 PM
HOW TO HAVE MACRO TYPE EMAIL ADDRESSES? petestrand Microsoft Word Help 1 July 30th 05 07:33 PM
How to merge without addresses ? Willie van Rensburg Mailmerge 1 June 17th 05 10:22 AM
cannot merge more than 30 addresses Alan Mailmerge 1 December 23rd 04 10:54 PM


All times are GMT +1. The time now is 04:10 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"