#  Other Applications & Softwares  > Word Formatting & General >  >  Mail Merge to Email

## NicoleAL123

Hi,

I started to write code for a mail merge, but it only seems to be working in the "Directory" format whereas I will need the final result in the "Email" format. In the example attachments, I will need to send out 3 emails (one per manufacturer) with the corresponding product list changing in each. For the first manufacturer, the email should look as follows (the red text is what needs to change every time the manufacturer name changes):

"Dear Joanne,  

We will need a list of these products sent in by November 23rd, 2017.

List of Products (Code --- Manufacturer --- Brand Name):

 123 --- ABC Food --- Gold
 345 --- ABC Food --- Orange

Thank you in advance for your assistance on this initiative. 

Jane Doe
(888) 876-6543"

The code currently written in the word document seems to ignore the email signature portion ("Thank you in advance...") and it puts each product in it's own email rather than grouping them together in one email per manufacturer. It also ignores the formatting (mainly the spaces between paragraphs).

Would anyone be able to help me edit this code in order to send out the 3 emails at once? 

Thank you in advance for your help!

Nicole

----------


## macropod

Directory merges cannot send their output to email. Word will have generated an error message to that effect.

That said, you can use Word's Catalogue/Directory Mailmerge facility for this (the terminology depends on the Word version). To see how to do so with any mailmerge data source supported by Word, check out my *Microsoft Word Catalogue/Directory Mailmerge Tutorial* at:
http://windowssecrets.com/forums/sho...merge-Tutorial
or:
http://www.gmayor.com/Zips/Catalogue%20Mailmerge.zip
The tutorial covers everything from list creation to the insertion & calculation of values in multi-record tables in letters. Do read the tutorial before trying to use the mailmerge document included with it.

Depending on what you're trying to achieve, the field coding for this can be complex. However, since the tutorial document includes working field codes for all of its examples, most of the hard work has already been done for you - you should be able to do little more than copy/paste the relevant field codes into your own mailmerge main document, substitute/insert  your own field names and adjust the formatting to get the results you desire.

Another option would be to use a DATABASE field in a normal letter mailmerge main document and a macro to drive the process. An example of this approach can be found at: http://answers.microsoft.com/en-us/o...1-1996c14dca5d
Conversely, if your workbook has a separate sheet with just a single instance of each of the grouping criteria, a DATABASE field in a normal letter mailmerge main document could be used without the need for a macro. For an example of that, see: https://answers.microsoft.com/en-us/...f-8642e46fa103 

Alternatively, you may want to try one of the Many-to-One Mail Merge add-ins, from:
Graham Mayor at http://www.gmayor.com/ManyToOne.htm; or
Doug Robbins at http://bit.ly/1hduSCB

----------


## NicoleAL123

Hi Paul,

This is very helpful, thank you! I think I am getting closer, but I am still not incredibly good at macros or mail merges so I think a bit of the code just needs to be tweaked but I am not sure what it is. Based off of your tutorial, I have created an email merge document and then a directory document with no spaces (saved to the same folder). I then ran the VBA code from the directory document, but I am getting the error "The requested member of the collection does not exist". I am assuming this has something to do with the format of the raw data in my excel file, but I am not sure. 

I then run the macro and DOES work to create the output I am looking for, but only in a separate word document and not in separate emails. Do you have any idea why the email portion of the macro isn't catching on? I have attached my newest files for reference.

Thanks!

Nicole

----------


## macropod

Your 'Email Merge Main Document.docx' file contains the field coding for a normal directory merge, not just the boilerplate text and the «Data» field (plus the «Recipient» field or equivalent, if used). It's also in the .docx format, whereas the instructions specify the .doc format.

Your 'Merge Code Test (Directory).docx‎' file also contains the field coding for a normal directory merge, not field coding like that described for an email merge. It, too is in the .docx format, but docx files cannot contain macros, which is what that document needs for the process to run.

----------


## NicoleAL123

Hi,

I have downloaded the files in your tutorial and am trying to execute the code using those instead before attempting to alter any code for my needs. However, I am still have issues. This is what I did:

First, I edited the document "Email Merge Main Document" to Mailings --> Select Recipients and connected this to the word document titled EmailDataSource. 

I then put in your suggested code (under "Merging by catalog/Directory to E-Mail") into the Mailmerge Main document and then selected Mailings --> Select Recipients and connected this to the excel file.

Still in this second file, I inserted a new module and pasted in the VBA code. When I run the code, I am receiving the following error: "Object Variable or With block variable not set" referring to the paragraph line of the following section of the code:

Sub EmailMergeTableMaker(DocName As Document)
Dim oTbl As Table, i As Integer, j As Integer, oRow As Row, oRng As Range, strTxt As String
With DocName
  .Paragraphs(1).Range.Delete

Any idea what I am missing?

Thanks!

----------


## macropod

You are quite clearly not following the instructions. Nowhere do they tell you to do this:




> I edited the document "Email Merge Main Document" to Mailings --> Select Recipients and connected this to the word document titled EmailDataSource



Indeed, had you followed the instructions to the letter, the 'EmailDataSource.doc' wouldn't even exist at that point.

Regarding:




> I then put in your suggested code (under "Merging by catalog/Directory to E-Mail") into the Mailmerge Main document and then selected Mailings --> Select Recipients and connected this to the excel file.



I don't see any indication you configured it for a Catalog/Directory mailmerge.

And as for:




> When I run the code, I am receiving the following error: "Object Variable or With block variable not set"



Since you only say you edited the 'Email Merge Main Document' and don't say you saved it in the .doc format as the instructions tell you to and my last post reiterated, the code can't be expected to work - so far as it's concerned, the document it's looking for doesn't exist.

----------


## NicoleAL123

Paul,

I apologize if I am frustrating you, but I read through your entire tutorial and perhaps am too much of a beginner for some of your language. In regards to your commentary, the two files from your zip were already configured under "E-Mail Messages" and "Directory" under the "Start Mail Merge" drop-down. Your files were also already saved in the .doc format, and I made no changes to either of those.

As for why I chose to use the "EmailDataSource" file as the connection, I did not see the "Recipient" field in any other file, and it was not listed anywhere in your instructions, so I came to that conclusion on my own.

I will look elsewhere for the answer to my question, but I appreciate your help.

----------


## macropod

> In regards to your commentary, the two files from your zip were already configured under "E-Mail Messages" and "Directory" under the "Start Mail Merge" drop-down. Your files were also already saved in the .doc format, and I made no changes to either of those.



That may be so, but your own attachments to post 3 were in the .docx format and the tutorial process, when applied to the sample documents included with the tutorial, works 100%.




> I will look elsewhere for the answer to my question



My reply in post #2 refers to alternate methods, including the use of a DATABASE field and the use of a Many-to-One Mail Merge add-in, for which two sources were provided.

----------

