Field in Subject Line Mail Merge Using Word 2010

rexhvn

New Member
Joined
Jan 7, 2016
Messages
27
Hi All,

I am hoping for some assistance please. I am wanting to add a data source from my excel spreadsheet into my subject line however I do not have the add on tool for Mail Merge.

Is there any other way I can do it such as VBA code? If so, help would be greatly appreciated.

Thanks,
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Correction:
You could do it with a macro like:
Code:
Sub Merge_To_Emails()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
  For i = 1 To .MailMerge.DataSource.RecordCount
    With .MailMerge
      .Destination = wdSendToEmail
      .SuppressBlankLines = True
      With .DataSource
        .FirstRecord = i
        .LastRecord = i
        .ActiveRecord = i
      End With
      .MailAddressFieldName = "Recipient_Email_Address"
      .MailSubject = .DataSource.DataFields("Subject_Line")
      .MailFormat = wdMailFormatHTML
      .Execute Pause:=False
    End With
  Next i
End With
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Thank you so much Paul, much appreciated.

I use the mail merge using both excel and word using the Mail Merge Step by Step wizard, could you let me know where I should input the code? VBA via excel or Word? I've got VBA experience but not sure how this works...

Thanks you.
 
Upvote 0
The macro is for Word, so you should add it to your mailmerge main document. Naturally, you will need to edit line lines:
.MailAddressFieldName = "Recipient_Email_Address"
.MailSubject = .DataSource.DataFields("Subject_Line")
to refer to your own field names.
 
Last edited:
Upvote 0
The macro is for Word, so you should add it to your mailmerge main document. Naturally, you will need to edit line lines:
.MailAddressFieldName = .DataSource.DataFields("Recipient_Email_Address")
.MailSubject = .DataSource.DataFields("Subject_Line")
to refer to your own field names.

Thanks Paul much appreciated.

I added this Macro into my main documents and edited the fields to reflect my spread sheet. Went through the Step by Step wizard as per ususal, went to the final stage and instead of sending it normally, I run the macro but got an error.

Error: Run-Time Error '5630' Word cannot merge documents that can be distributed via mail or fax without a valid mail address. Chose the setup button to select a mail address data field.

I would also like a set a default email address that these are being sent from.

All help is appreciated.
 
Upvote 0
Did you edit 'Recipient_Email_Address' as advised?

You cannot specify a default 'send' email address in code; the only way to change the default is by changing the default email account of the user sending the emails.
 
Last edited:
Upvote 0
I found this to work when I replaced the line

.MailAddressFieldName = "Recipient_Email_Address"

with

.MailAddressFieldName = "Email"

credit goes for the solution goes to Macropod for the original solution posted here and Bluejay07 for the edit at https://www.tek-tips.com/viewthread.cfm?qid=1714151 posted on 12 Jul 13 15:56


The following is the code I'm using

Code:
Sub Merge_To_Emails()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
  For i = 1 To .MailMerge.DataSource.RecordCount
    With .MailMerge
      .Destination = wdSendToEmail
      .SuppressBlankLines = True
      With .DataSource
        .FirstRecord = i
        .LastRecord = i
        .ActiveRecord = i
      End With
      .MailAddressFieldName = "email"
      .MailSubject = .DataSource.DataFields("Subject")
      .MailFormat = wdMailFormatHTML
      .Execute Pause:=False
    End With
  Next i
End With
Application.ScreenUpdating = True
End Sub

This was my first time making a macro. So note to newbies to use this code you have to click on the Macros button in word go to create a macro name that is appropriate or use
Merge_To_Emails to keep changes to a minimum
 
Last edited by a moderator:
Upvote 0
Hi folks

I have tried using this in word, can I add a CC field? When I run the macro nothing happens, which areas to I need to change to point to my source spreadsheet?

Thanks :)
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top