#1
|
|||
|
|||
VBA code to CC multiple people in mail merge by word
I have difficulties in writing a VBA code that allow the mail merge to cc people that I would like to loop in. I’ve checked this one (https://www.msofficeforums.com/mail-...ilmerge-3.html) but have no idea which rows to delete as I do no need to send it out with attachment. My situation is: - To e-mail in cell A1 and copy people in A2, A3... if it’s not blank and so on...... Currently I’ve applied a code that allows me to adapt dynamic subject line... |
#2
|
||||
|
||||
To omit attachments, you could simply delete:
Code:
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Code:
Dim WithEvents wdapp As Application Dim EMAIL_SUBJECT As String Dim FIRST_RECORD As Boolean Private Sub Document_Open() Set wdapp = Application ThisDocument.MailMerge.ShowWizard 1 End Sub Private Sub Document_Close() Set wdapp = Nothing End Sub Private Sub wdapp_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean) Dim i As Integer With ActiveDocument.MailMerge If FIRST_RECORD = True Then EMAIL_SUBJECT = .MailSubject FIRST_RECORD = False Else .MailSubject = EMAIL_SUBJECT End If i = .DataSource.DataFields.Count Do While i > 0 .MailSubject = Replace(.MailSubject, "<" & .DataSource.DataFields(i).Name & ">", .DataSource.DataFields(i).Value, , , vbTextCompare) i = i - 1 Loop End With End Sub Private Sub wdapp_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean) FIRST_RECORD = True End Sub Private Sub wdapp_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult As Document) ActiveDocument.MailMerge.MailSubject = EMAIL_SUBJECT End Sub Additionally, do i need to change anything in your provided code (as i saw there is a ".Cell(j,i)". Thanks for your help anyway *** if needed, i could put my sample doc here for your kind checking.... my purpose is to send out email by mail merge with a dynamic subject while copying the right personnel in each individual email, i know that's crazy but wanna complete this in a very short time....typing out each email takes time............ Last edited by kuankailok; 05-04-2020 at 05:54 AM. Reason: added some more comments |
#4
|
||||
|
||||
The code you've posted is nothing like the code discussed in the link you posted. All that means is you've wasted my time. Waste someone else's - preferably your own.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word Mail Merge Envelope Addresses with Multiple Conditions | Pedro007 | Mail Merge | 2 | 11-19-2019 07:25 AM |
Mail Merge Student Transcript - Multiple Years from multiple sheets | aizah2018 | Mail Merge | 1 | 11-11-2018 01:27 AM |
Mail Merge Code Issue | Andrewwill | Mail Merge | 6 | 01-06-2018 10:25 PM |
Mail Merge to multiple employees in multiple locations as PDF by location | GFiz | Mail Merge | 1 | 05-13-2017 08:01 PM |
Mail Merge Multiple Rows -word(from Spain) | luisaranda | Mail Merge | 6 | 03-06-2016 09:32 AM |