Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Claudia Claudia is offline
external usenet poster
 
Posts: 18
Default Add a Cc column to mailmerge

I have a rather large excel spreadsheet that I use as the data source for a
quarterly mailmerge. Is there a way I can add a Cc column to my spreadsheet
instead of adding a new row for each new email recipient? I have seen Doug
Robbins macro for emailing with attachments and, frankly, I'm not bright
enough to figure out how to apply it to my mailmerge. Can this macro be used
on my existing mailmerge document?

http://word.mvps.org/FAQs/MailMerge/...ttachments.htm

Thanks,
Claudia
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Add a Cc column to mailmerge

It's probably worth going through Doug's method step by step as it's a good
general-purpose method which I know he uses (or perhaps used) a lot,
whereas the following macros are nothing like as well tested (well, in fact
the versions I've posted here havne't been tested at all). If it's the
macros themselves that make it hard to follow, that's a problem as I don't
think you can do this without them.

If you are merging to Outlook (not Outlook Express) you may be able to do
something slightly simpler using a VBA macro to do "one merge per data
source record" - i.e. this won't work for more complex merges where you have
{ NEXT }, { NEXTIF } and probably { SKIP } or { SKIPIF } fields.

You need to put your list of CC addresses into a column in Excel where each
address except perhaps the last is terminated by a semi-colon ";". Let's say
this field is called "CC"

e.g. ;

Personally I would suggest that you stick to using a plain text body, for
which you can try something based on the following VBA. You will need to use
Word VB Editor's Tools|References option to add the Outlook Library as a
reference (if Macros are really unfamiliar, see e.g.

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm
)



Sub EmailOneDocPerSourceRecWithBody()
Dim bOutlookStarted As Boolean
Dim bTerminateMerge As Boolean
Dim intSourceRecord As Integer
Dim objMailItem As Outlook.MailItem
Dim objMerge As Word.MailMerge
Dim objOutlook As Outlook.Application
Dim strMailCC As String
Dim strMailSubject As String
Dim strMailTo As String
Dim strMailBody As String
Dim strOutputDocumentName As String

bOutlookStarted = False
bTerminateMerge = False

' Set up a reference to the
' Activedocument, partly because
' the ActiveDocument changes as you
' merge each record

Set objMerge = ActiveDocument.MailMerge

' Start Outlook as necessary

On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err 0 Then
Set objOutlook = CreateObject("Outlook.Application")
bOutlookStarted = True
End If

With objMerge

' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the
' document, you should not need to
' define it here.

' .OpenDataSource _
' Name:="whatever"

intSourceRecord = 1

Do Until bTerminateMerge
.DataSource.ActiveRecord = intSourceRecord

' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to

If .DataSource.ActiveRecord intSourceRecord Then
bTerminateMerge = True
' the record exists
Else

' while we are looking at the
' correct activerecord,
' create the mail subject, body, "to" and "cc"
' Just some sample code here - replace it with
' whatever you need. But ensure that the field names
' match the ones in your data source exactly - uppercase/lowercase
' differences are significant here

strMailSubject = _
"Results for " & _
objMerge.DataSource.DataFields("Firstname") & _
" " & objMerge.DataSource.DataFields("Lastname")
strMailBody = _
"Dear " & objMerge.DataSource.DataFields("Firstname") & _
vbCrLf & _
"Please find attached a Word document containing" & vbCrLf & _
"your results for..." & vbCrLf & _
vbCrLf & _
"Yours" & vbCrLf & _
"Your name"
strMailTo = objMerge.DataSource.DataFields("Emailaddress")
strMailCC = objMerge.DataSource.DataFields("CC")

' create the document path name
' In this case it can be the same for every recipient,
' but if you want to retain copies of the
' document, you can use info. in the data source

' this is an example - insert your
' own pathname here

strOutputDocumentName = "c:\a\results.doc"

' strOutputDocumentName = _
' "c:\mymergeletters\_" & _
' .DataSource.DataFields("Lastname").Value & _
' " letter.doc"
.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the
' output document

' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close

' Now create a mail item

Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
.Subject = strMailSubject
.Body = strMailBody
.To = strMailTo
.CC = strMailCC
.Attachments.Add strOutputDocumentName, olByValue, 1
'.Save
.Send
End With
Set objMailItem = Nothing

intSourceRecord = intSourceRecord + 1
End If
Loop
End With

' Close Outlook if appropriate

If bOutlookStarted Then
objOutlook.Quit
End If

Set objOutlook = Nothing
Set objMerge = Nothing

End Sub


However, if you need an HTML body, try starting with (the rather similar)

Sub EmailOneHTMLPagePerSourceRecWithBody()
' By Peter Jamieson, 2006
Dim bOutlookStarted As Boolean
Dim bTerminateMerge As Boolean
Dim intSourceRecord As Integer
Dim objMailItem As Outlook.MailItem
Dim objMerge As Word.MailMerge
Dim objOutlook As Outlook.Application
Dim strMailCC As String
Dim strMailSubject As String
Dim strMailTo As String
Dim strMailBody As String
Dim strOutputDocumentName As String


bOutlookStarted = False
bTerminateMerge = False


' Set up a reference to the
' Activedocument, partly because
' the ActiveDocument changes as you
' merge each record


Set objMerge = ActiveDocument.MailMerge


' Start Outlook as necessary


On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err 0 Then
Set objOutlook = CreateObject("Outlook.Application")
bOutlookStarted = True
End If


With objMerge


' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the
' document, you should not need to
' define it here.


' .OpenDataSource _
' Name:="whatever"


intSourceRecord = 1


Do Until bTerminateMerge
.DataSource.ActiveRecord = intSourceRecord


' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to


If .DataSource.ActiveRecord intSourceRecord Then
bTerminateMerge = True
' the record exists
Else


' while we are looking at the
' correct activerecord,
' create the mail subject, body, "to" and "cc"
' Just some sample code here - replace it with
' whatever you need. But ensure that the field names
' match the ones in your data source exactly - uppercase/lowercase
' differences are significant here

strMailSubject = _
"Results for " & _
objMerge.DataSource.DataFields("Firstname") & _
" " & objMerge.DataSource.DataFields("Lastname")

' Use a simple sample
strMailBody = "HTMLBODYTABLE
BORDER=5TRTDk/TDTDt/TD/TR/TABLE/BODY/HTML"
strMailTo = objMerge.DataSource.DataFields("Emailaddress")
strMailCC = objMerge.DataSource.DataFields("CC")

' create the document path name
' In this case it can be the same for every recipient,
' but if you want to retain copies of the
' document, you can use info. in the data source

' this is an example - insert your
' own pathname here

strOutputDocumentName = "c:\a\results.htm"

' strOutputDocumentName = _
' "c:\mymergeletters\_" & _
' .DataSource.DataFields("Lastname").Value & _
' " letter.doc"
.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the
' output document

' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName, wdFormatFilteredHTML
ActiveDocument.Close

' Now create a new Mail Item

Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
.BodyFormat = olFormatHTML
.Subject = strMailSubject
.HTMLBody = strMailBody
.To = strMailTo
.CC = strMailCC
.Attachments.Add strOutputDocumentName, olByValue, 1
.Save
.Send
End With
Set objMailItem = Nothing

intSourceRecord = intSourceRecord + 1
End If
Loop
End With

' Close Outlook if appropriate

If bOutlookStarted Then
objOutlook.Quit
End If

Set objOutlook = Nothing
Set objMerge = Nothing

End Sub


--
Peter Jamieson
http://tips.pjmsn.me.uk

"Claudia" wrote in message
...
I have a rather large excel spreadsheet that I use as the data source for a
quarterly mailmerge. Is there a way I can add a Cc column to my
spreadsheet
instead of adding a new row for each new email recipient? I have seen
Doug
Robbins macro for emailing with attachments and, frankly, I'm not bright
enough to figure out how to apply it to my mailmerge. Can this macro be
used
on my existing mailmerge document?

http://word.mvps.org/FAQs/MailMerge/...ttachments.htm

Thanks,
Claudia


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Claudia Claudia is offline
external usenet poster
 
Posts: 18
Default Add a Cc column to mailmerge

Thank you Peter! I will attempt to dissect yours and Doug's macros again
this afternoon. With luck I will be able to figure this out.

"Peter Jamieson" wrote:

It's probably worth going through Doug's method step by step as it's a good
general-purpose method which I know he uses (or perhaps used) a lot,
whereas the following macros are nothing like as well tested (well, in fact
the versions I've posted here havne't been tested at all). If it's the
macros themselves that make it hard to follow, that's a problem as I don't
think you can do this without them.

If you are merging to Outlook (not Outlook Express) you may be able to do
something slightly simpler using a VBA macro to do "one merge per data
source record" - i.e. this won't work for more complex merges where you have
{ NEXT }, { NEXTIF } and probably { SKIP } or { SKIPIF } fields.

You need to put your list of CC addresses into a column in Excel where each
address except perhaps the last is terminated by a semi-colon ";". Let's say
this field is called "CC"

e.g. ;

Personally I would suggest that you stick to using a plain text body, for
which you can try something based on the following VBA. You will need to use
Word VB Editor's Tools|References option to add the Outlook Library as a
reference (if Macros are really unfamiliar, see e.g.

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm
)



Sub EmailOneDocPerSourceRecWithBody()
Dim bOutlookStarted As Boolean
Dim bTerminateMerge As Boolean
Dim intSourceRecord As Integer
Dim objMailItem As Outlook.MailItem
Dim objMerge As Word.MailMerge
Dim objOutlook As Outlook.Application
Dim strMailCC As String
Dim strMailSubject As String
Dim strMailTo As String
Dim strMailBody As String
Dim strOutputDocumentName As String

bOutlookStarted = False
bTerminateMerge = False

' Set up a reference to the
' Activedocument, partly because
' the ActiveDocument changes as you
' merge each record

Set objMerge = ActiveDocument.MailMerge

' Start Outlook as necessary

On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err 0 Then
Set objOutlook = CreateObject("Outlook.Application")
bOutlookStarted = True
End If

With objMerge

' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the
' document, you should not need to
' define it here.

' .OpenDataSource _
' Name:="whatever"

intSourceRecord = 1

Do Until bTerminateMerge
.DataSource.ActiveRecord = intSourceRecord

' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to

If .DataSource.ActiveRecord intSourceRecord Then
bTerminateMerge = True
' the record exists
Else

' while we are looking at the
' correct activerecord,
' create the mail subject, body, "to" and "cc"
' Just some sample code here - replace it with
' whatever you need. But ensure that the field names
' match the ones in your data source exactly - uppercase/lowercase
' differences are significant here

strMailSubject = _
"Results for " & _
objMerge.DataSource.DataFields("Firstname") & _
" " & objMerge.DataSource.DataFields("Lastname")
strMailBody = _
"Dear " & objMerge.DataSource.DataFields("Firstname") & _
vbCrLf & _
"Please find attached a Word document containing" & vbCrLf & _
"your results for..." & vbCrLf & _
vbCrLf & _
"Yours" & vbCrLf & _
"Your name"
strMailTo = objMerge.DataSource.DataFields("Emailaddress")
strMailCC = objMerge.DataSource.DataFields("CC")

' create the document path name
' In this case it can be the same for every recipient,
' but if you want to retain copies of the
' document, you can use info. in the data source

' this is an example - insert your
' own pathname here

strOutputDocumentName = "c:\a\results.doc"

' strOutputDocumentName = _
' "c:\mymergeletters\_" & _
' .DataSource.DataFields("Lastname").Value & _
' " letter.doc"
.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the
' output document

' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close

' Now create a mail item

Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
.Subject = strMailSubject
.Body = strMailBody
.To = strMailTo
.CC = strMailCC
.Attachments.Add strOutputDocumentName, olByValue, 1
'.Save
.Send
End With
Set objMailItem = Nothing

intSourceRecord = intSourceRecord + 1
End If
Loop
End With

' Close Outlook if appropriate

If bOutlookStarted Then
objOutlook.Quit
End If

Set objOutlook = Nothing
Set objMerge = Nothing

End Sub


However, if you need an HTML body, try starting with (the rather similar)

Sub EmailOneHTMLPagePerSourceRecWithBody()
' By Peter Jamieson, 2006
Dim bOutlookStarted As Boolean
Dim bTerminateMerge As Boolean
Dim intSourceRecord As Integer
Dim objMailItem As Outlook.MailItem
Dim objMerge As Word.MailMerge
Dim objOutlook As Outlook.Application
Dim strMailCC As String
Dim strMailSubject As String
Dim strMailTo As String
Dim strMailBody As String
Dim strOutputDocumentName As String


bOutlookStarted = False
bTerminateMerge = False


' Set up a reference to the
' Activedocument, partly because
' the ActiveDocument changes as you
' merge each record


Set objMerge = ActiveDocument.MailMerge


' Start Outlook as necessary


On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err 0 Then
Set objOutlook = CreateObject("Outlook.Application")
bOutlookStarted = True
End If


With objMerge


' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the
' document, you should not need to
' define it here.


' .OpenDataSource _
' Name:="whatever"


intSourceRecord = 1


Do Until bTerminateMerge
.DataSource.ActiveRecord = intSourceRecord


' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to


If .DataSource.ActiveRecord intSourceRecord Then
bTerminateMerge = True
' the record exists
Else


' while we are looking at the
' correct activerecord,
' create the mail subject, body, "to" and "cc"
' Just some sample code here - replace it with
' whatever you need. But ensure that the field names
' match the ones in your data source exactly - uppercase/lowercase
' differences are significant here

strMailSubject = _
"Results for " & _
objMerge.DataSource.DataFields("Firstname") & _
" " & objMerge.DataSource.DataFields("Lastname")

' Use a simple sample
strMailBody = "HTMLBODYTABLE
BORDER=5TRTDk/TDTDt/TD/TR/TABLE/BODY/HTML"
strMailTo = objMerge.DataSource.DataFields("Emailaddress")
strMailCC = objMerge.DataSource.DataFields("CC")

' create the document path name
' In this case it can be the same for every recipient,
' but if you want to retain copies of the
' document, you can use info. in the data source

' this is an example - insert your
' own pathname here

strOutputDocumentName = "c:\a\results.htm"

' strOutputDocumentName = _
' "c:\mymergeletters\_" & _
' .DataSource.DataFields("Lastname").Value & _
' " letter.doc"
.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the
' output document

' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName, wdFormatFilteredHTML
ActiveDocument.Close

' Now create a new Mail Item

Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
.BodyFormat = olFormatHTML
.Subject = strMailSubject
.HTMLBody = strMailBody
.To = strMailTo
.CC = strMailCC
.Attachments.Add strOutputDocumentName, olByValue, 1
.Save
.Send
End With
Set objMailItem = Nothing

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
Selecting a column: some rows have 2 cells in 1 column? DonD Tables 4 June 15th 06 03:29 AM
How do I change a text column to a number column when merging? Parish Secretary Microsoft Word Help 1 January 27th 06 05:05 PM
format footnote to no-column header followed by column Illinois Microsoft Word Help 2 November 22nd 05 07:41 PM
How to paste a column of text into a column in a Word Table Sam Page Layout 2 July 31st 05 08:03 PM
After a column break, why does the next column double space? Beaner_Teach Page Layout 8 July 4th 05 02:12 PM


All times are GMT +1. The time now is 03:38 AM.

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"