View Single Post
  #17   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 MS Word Email Merge with Attachements

I suspect that you have missed the step of executing the merge of the
document that contains the text for the body of the email messages to a new
document. It is when you that new document as the active document, that you
run the macro.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
"Ivan Woyno" wrote in message
...
Good afternoon Peter,

I was able to finally get past the Outlook Object Library problem
discussed here and the macro asks me for the table with e-mails and
attachments, however, I do not receive an email warning message and after
a few seconds the screens comes up with a text box that states:

Microsfot Word

0 Messages have been sent.

On the Directory (titled dir1) I have a table with three rows and two
columns

Column one: email address
Column two: attachment path

The e-mail text is one the active document window

Nothing appears to fail, it just doesn't seem to send out the e-mail.

Any ideas what I am missing?

Ivan



Dav wrote:

Thanks Peter, Will try this out and let you know how i get on.
14-Feb-09

Thanks Peter,
Will try this out and let you know how i get on. Again i cannot say how
much
i appreciate the help.

Have a Great day.
"Peter Jamieson" wrote:

Previous Posts In This Thread:

On Thursday, February 12, 2009 4:19 PM
Dav wrote:

MailMerge with Attachements
I have searched the internet and have found very little on this that
actually
makes sense to me.

What i'm trying to do is create a mailmerge with say around 350
receipients,
each with an individual attachment. I have tried using this tutorial
http://word.mvps.org/FAQs/MailMerge/...ttachments.htm but for the
life
of me i can't get this to work. Can anyone please help me with this? or
is
there different way of doing this?

On Thursday, February 12, 2009 5:55 PM
Peter Jamieson wrote:

1. Where do you get stuck?
1. Where do you get stuck?

2. Are your attachments defined prior to the merge (i.e. you have a
bunch of files and somewhere you're going to have to say which recipient
should get which attachment) or are you expecting the merge process
itself to generate the attachments?

Peter Jamieson

http://tips.pjmsn.me.uk

Dave wrote:

On Friday, February 13, 2009 2:40 PM
Dav wrote:

Hi Peter,I haven't been able to get anything from the tutorial to work, I
get
Hi Peter,
I haven't been able to get anything from the tutorial to work, I get the
ususal compile errors.I just don't understand the tutorial at all. (like
alot
of other users).

Can you help?

i'm using word2007
i have a folder full of the individual attachements.
"Peter Jamieson" wrote:

On Friday, February 13, 2009 5:44 PM
Peter Jamieson wrote:

Well, in order to do that, I will try to work backwards through the
procedure,
Well, in order to do that, I will try to work backwards through the
procedure, because then the reason for each step may become a little
clearer.

I'm also going to split the description into 2 parts:
a. Getting the macro to work with some simple test data. This is to
concentrate on what the macro does (partly because you have those errors
when you try to run it) and skips the whole issue of how you actually
use mailmerge to create the files that you need.
b. How to prepare the data that the macro needs.

I'm only going to do part (a) now, partly because I don't have time to
finish right now, and partly to give us a breather. If all goes OK,
perhaps it will be enough for you to understand how the whole thing is
supposed to work, in which case we won't need part (b). But let's see.

Using this method, I suggest you do not try to grasp the entire process
in one go. Work through it step by step. At least if you get stuck, you
will probably be able to identify where and why.

The main prerequisites are that you have a version of Word that lets you
use Word VBA, and Outlook (not Outlook Express).

I'm also going to make a simplification by assuming that you want one,
and only one, attachment in each email.

Please try not to glaze over :-)

1. What does the emailmergewithattachments macro actually do?

Overview
--------
Let's suppose you want to merge to email with one attachment per email,
to 10 recipients.

The emailmergewithattachments macro has two main inputs:
a. a table that contains 10 rows, one for each recipient, and two
columns. Column 1 contains the email addresses of the recipients, and
column 2 contains the pathname of the attachment that you want to send
to that recipient. Let's call this the Attachment Table.
b. a Word document that has 10 Word sections. Section 1 contains the
text that you want to put in the message body of the email to recipient
1, section 2 contains the text that you want to put in the message body
of the email to recipient 2, and so on. Let's call this the Message
Bodies Document

It has one main output: 10 email messages, one for each recipient in the
list, sent via Outlook.

Some important details
----------------------
a. For this macro to work, the Attachment Table has to be in the form
of a Word document that contains that 10-row, 2-column table.
b. The macro prompts for the filename of the Attachment Table
c. the macro assumes that the "active document" (typically the Word
document open in front of you) is the Message Bodies Document.
d. The macro also prompts for the subject, which will be the same in
all the messages

2. To test that, it doesn't matter how we create the Attachment Table
and the Message Bodies Document. We just need them to exist and contain
the right kind of data.

So as an experiment, I suggest you try the following, which would allow
the macro to do the final part of a "merge to email with attachments",
but only to 2 recipients:

I. Create an Attachment Table
a. create a Word document called testat.docx, containing a table with
2 rows and 2 columns
b. in row1, column1, put your own e-mail address.
c. in row1, column2, put the full pathname of an attachment you want
to send to yourself
d. ditto for row2
e. save and close the document

II. create a Message Bodies Document
a. create a Word "macro-enabled" document called testmb.docm.
b. type "Test body of message 1"
c. insert a Section Break. You can use Page layout-Page
Setup-breaks-Next page
d. Type "Test body of message 2"
e. save the document, but leave it open.

III. Install the macro code

We're going to try to install the macro in the Message Bodies Document.

In Word 2007, ensure that the Developer tab is available. If not, check
Word-Office Button-Word Options-Popular-Show Developer tab in the
Ribbon
a. Click Developer-Visual basic

In any of these versions,
b. Look down the "Projects" pane near the top left for "Project
(Testmb)" and select it
c. Click Insert-Module. You should see Modules and Module1 appear
somewhere not far below "Project (Testmb)"
d. Open Doug's web page at
http://word.mvps.org/FAQs/MailMerge/...ttachments.htm, locate and
select the macro code, and use ctrl-C to copy the code to the clipboard.
e. Back in the visual basic editor, Select Module1, then look at the
empty pane to the right of the projects pane. You should see dropdowns
showing (General) and (Declarations) above it. Click in the empty pane
and click ctrl-V to paste Doug's code in.
f. In the Visual Basic editor, click File-Save testmb . This saves
the .doc/.docm file, but leaves you "in the editor window"

IV. Make the reference to Outlook

This is just one of those things you have to do to make the whole thing
work.

g. In the visual basic editor, click Tools-References. The VB editor
displays a list of "references" available on your system.
h. Scroll down the list until you see something like "Microsoft
Outlook 12.0 Object Library" (assuming you are using Outlook 2007)
i. Check the box to the left of that name
j. Click OK to make the reference (which doesn't appear anywhere
obvious) and dismiss the dialog box.
k. In the Visual Basic editor, click File-Save testmb to save the
.docm file again

V. Recap.

At this point, you should be looking at the Visual Basic Editor.

The macro code for the emailmergewithattachments macro is displayed.

Somewhere behind the Visual Basic Editor, the document testmb.docm,
containing the Message Bodies, is open in a Word Window. This should be
the Active Document. Find it and click in it if you want, just to be
sure, then click again in the Visual basic Editor's cod window that
contains the emailmergewithattachments macro.

The Attachment Table is sitting there in a document called testat.docx,
but is currently closed.

VI. Run the macro.

In the Visual Basic Editor, press F5 to start the macro (or click the
"Run" arrow button if you are familiar with the VB environment and
prefer that.

If all goes well, there should be a delay if Word needs to start
Outlook, then you should see a dialog box titled "File"

Locate and select testat.docx, then click Open

If there are no problems, you should see a dialog box titled "Email
subject input"

Type "Test messages 1" in the text box and click OK.

At this point, I would expect you to see the security dialog titled
"Microsoft Office Outlook". There are actually two different messages -
depending on various factors you might see both. One says that a program
is trying to send email on your behalf, and you have to Allow that, and
the other one says that a program is trying to access your address book
(or some such) and yu can specify that it should have access for so many
minutes. In other words, if you aren't familiar with these messages,
read them, then do what is necessary to get through them.

You should receive one or two alerts about messages being sent.

And that's the end of "part (a)". You will probably want to verify that
Word has sent the two messages and attachments that you expect.

If you managed that, but still need "part (b)", let me know and I'll try
to go through it a.s.a.p (probably won't be until tomorrow). If not,
maybe you can describe what went wrong and we'll keep trying until we
can get through this test, or are otherwise exhausted :-)

Peter Jamieson

http://tips.pjmsn.me.uk

Dave wrote:

On Saturday, February 14, 2009 1:19 AM
Graham Mayor wrote:

MailMerge with Attachements
If http://www.gmayor.com/installing_macro.htm doesn't help with the keying
errors in your macro, note that MAPILab's Mailmerge toolkit add-in for
Outlook http://www.mapilab.com/outlook/mail_merge/ will for a modest sum
take the effort out of merging attachments.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Dave wrote:

On Saturday, February 14, 2009 6:33 AM
Dav wrote:

Hey Peter,This has really helped me alot.
Hey Peter,

This has really helped me alot. Looks easier to follow than the published
tutorial. I will try this out today and let you know how it turns out.
Thanks again for taking the time out to write this for me.
Have a great day.

"Peter Jamieson" wrote:

On Saturday, February 14, 2009 7:29 AM
Dav wrote:

Hey Peter,Followed your instructions to the letter. No luck still.
Hey Peter,

Followed your instructions to the letter. No luck still. Still getting
user defined errors? any suggestion?

"Peter Jamieson" wrote:

On Saturday, February 14, 2009 7:58 AM
Peter Jamieson wrote:

Where in the process did you get to?
Where in the process did you get to?

If you had got to the point where you were running the macro, did you
a. see any evidence that Outlook was starting?
b. see the prompt for the "Attachment table file name" ?

or what?

Peter Jamieson

http://tips.pjmsn.me.uk

Dave wrote:

On Saturday, February 14, 2009 8:24 AM
Dav wrote:

Ok, got it to work. thx very much.
Ok, got it to work. thx very much. just a question though, if i want the
mail to be sent from a different address is there a way to be able to
select
the email address its set from?

"Peter Jamieson" wrote:

On Saturday, February 14, 2009 8:40 AM
Peter Jamieson wrote:

Good.
Good.

if i want the
mail to be sent from a different address is there a way to be able to

select
the email address its set from?


1. For one thing, as I undertand it the MAPILabs toolkit mentioned by
Graham Mayor in his response to this thread has a facility to do this.

2. Otherwise, it depends on what you mean. Unless you're connected to
Microsoft exchange, the macro will only send from the Outlook /profile/
you are currently logged into. If

3. However, if all you need is the "Reply-to" to be set to a different
address, if you have control over your own email /account/ settings you
should be able to change that address.

4. If you are working via Microsoft Exchange and you have "Send As" or
"Send As Delegate" permission for another user account, then you should
be able to set

objMailItem.SentOnBehalfOfName = "the Exchange user name you want to use"

And send the item. In that case, the item does not necessarily appear as
"a sent on behalf of" item. If you have "Send As" permission, it appears
as if it's from the user you specified in SentOnBehalfOfName and there
is no "on behalf of" - the same is true if you fill in the "From"

And that's about all I know...

Peter Jamieson

http://tips.pjmsn.me.uk

Dave wrote:

On Saturday, February 14, 2009 9:07 AM
Dav wrote:

Thanks Peter,I will be working from an exchange address and have "Send
As" or
Thanks Peter,

I will be working from an exchange address and have "Send As" or
"Send As Delegate" permission for another user account . where do i put in
objMailItem.SentOnBehalfOfName = "the Exchange user name you want to use"
?
"Peter Jamieson" wrote:

On Saturday, February 14, 2009 9:40 AM
Peter Jamieson wrote:

You need to add a line to Doug's code, and in there it will look a bit
You need to add a line to Doug's code, and in there it will look a bit
different from the line I gave.

e.g., add a line to Doug's code


Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.Body = Source.Sections(j).Range.Text

so that it reads

Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.Body = Source.Sections(j).Range.Text
.SentOnBehalfOfName = "the Exchange user name you want to use"


Obviously, you have to insert the correct name instead of "the Exchange
user name you want to use"

I certainly can't guarantee that that will work, and I'm not currently
in a position to investigate if it does not, but I was able to do it
with my own copy of Exchange when I looked this area a year or two ago.


Peter Jamieson

http://tips.pjmsn.me.uk

Dave wrote:

On Saturday, February 14, 2009 10:02 AM
Dav wrote:

Thanks Peter,one more thing, do we always have to do the page break
manually
Thanks Peter,
one more thing, do we always have to do the page break manually to add the
body of the mail? i have 350 users to send out the mails to each with a
little bit of different text and attachement. Was there another part to
the
merge?

"Peter Jamieson" wrote:

On Saturday, February 14, 2009 2:01 PM
Dav wrote:

Thanks Peter, Will try this out and let you know how i get on.
Thanks Peter,
Will try this out and let you know how i get on. Again i cannot say how
much
i appreciate the help.

Have a Great day.
"Peter Jamieson" wrote:

EggHeadCafe - Software Developer Portal of Choice
Seamless Data Compression in .NET
http://www.eggheadcafe.com/tutorials...mpression.aspx