Word e-mail Merge & Sending Attachments

  Taff36 08:30 28 Sep 2005
Locked

I have a database of Society Members and I want to e-mail merge a letter and attach two files to the e-mail. I don`t have a problem sending just the message but I can`t seem to fathom out how I automatically attach a couple of additional Word documents.

Word 2003 and Outlook 2003

  MAJ 08:59 28 Sep 2005

Does this help click here , Taff36?

  Taff36 09:31 28 Sep 2005

That looks good. I`ll try that out whilst I`m on the train later and let you know. Thanks.

  Taff36 08:43 04 Oct 2005

I struggled with this over the weekend. Although I have set up the Catalogue (Directory) I have struggled with saving the macro. I copied the macro from the link and pasted it into my macros in Word however it won`t run properly and goes into debugging. Does that macro need some form of editing? Here`s what Ive got:

Subemailmergewithattachments()

DimSourceAsDocument,MaillistAsDocument
DimDatarangeAsRange
DimCounterAsInteger,iAsInteger
DimbStartedAsBoolean
DimoOutlookAppAsOutlook.Application
DimoItemAsOutlook.MailItem
DimmysubjectAsString,messageAsString,titleAsString

SetSource=ActiveDocument

'CheckifOutlookisrunning.Ifitisnot,startOutlook
OnErrorResumeNext
SetoOutlookApp=GetObject(,"Outlook.Application")
IfErr<>0Then
SetoOutlookApp=CreateObject("Outlook.Application")
bStarted=True
EndIf

'Openthecatalogmailmergedocument
WithDialogs(wdDialogFileOpen)
.Show
EndWith
SetMaillist=ActiveDocument

'Showaninputboxaskingtheuserforthesubjecttobeinsertedintotheemailmessages

message="Enterthesubjecttobeusedforeachemailmessage."'Setprompt.
title="EmailSubjectInput"'Settitle.
'Displaymessage,title
mysubject=InputBox(message,title)

'Iteratethroughtherowsofthecatalogmailmergedocument,extractingtheinformation
'tobeincludedineachemail.
Counter=1
WhileCounter<=Maillist.Tables(1).Rows.Count
Source.Sections.First.Range.Cut
Documents.Add
Selection.Paste
SetoItem=oOutlookApp.CreateItem(olMailItem)
WithoItem
.Subject=mysubject
.Body=ActiveDocument.Content
SetDatarange=Maillist.Tables(1).Cell(Counter,1).Range
Datarange.End=Datarange.End-1
.To=Datarange
Fori=2ToMaillist.Tables(1).Columns.Count
SetDatarange=Maillist.Tables(1).Cell(Counter,i).Range
Datarange.End=Datarange.End-1
.Attachments.AddTrim(Datarange.Text),olByValue,1
Nexti
.Send
EndWith
SetoItem=Nothing
ActiveDocument.ClosewdDoNotSaveChanges
Counter=Counter+1
Wend

'CloseOutlookifitwasstartedbythismacro.
IfbStartedThen
oOutlookApp.Quit
EndIf

'Cleanup
SetoOutlookApp=Nothing
Source.ClosewdDoNotSaveChanges
Maillist.ClosewdDoNotSaveChanges

EndSub

  MAJ 08:52 04 Oct 2005

VBA is a total mystery to me, Taff36, I'm sure someone will be along shortly that knows more about it. :-(

  Taff36 09:47 04 Oct 2005

Me Too! Thanks for the link anyway.

  Taff36 07:45 05 Oct 2005

Bump

  VoG II 08:37 05 Oct 2005

There's a lot of spaces missing in that code - maybe a result of the formatting on this site. For example

DimSourceAsDocument

should be

Dim Source As Document

In the Visual Basic Editor, Tools|References and make sure Microsoft Outlook <version> Object Library is ticked.

  Taff36 09:04 05 Oct 2005

Thanks VoG. I`ve checked my macro which I copied and pasted from Maj`s first link. It too is missing the spaces so the formatting needs checking against the original.

Object Library is ticked OK. Will let you know how I get on.

  Taff36 08:12 18 Oct 2005

Never quite got to grips with this one. In the end I e-mail merged from Outlook using Word as my editor. I had to define the worksheet fields and created a seperate address book for the members with just their names and e-mail addresses. Then I set up three distribution lists within the address book each with about 100 names in it - my ISP limits the number of recipients to 200 but with 4 attachments I thought I`d play safe. I then simply wrote the newsletter in Word, copied it to the e-mail, attached 4 files and sent it to the three distribution lists.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Fujitsu Lifebook P727 laptop review

Converse's new logo: the trainer brand looks to its heritage for a fresh identity

Mac power user tips and hidden tricks

Comment lancer Windows 10 en mode sans ├ęchec ?