Mail Merge to email with attachments

K

KimS

I found instructions for using mail merge in Word to send multiple emails
with attachments ("Mail Merge to E-mail with Attachments" by Doug Robbins).
The macro generates an error and I have not been able to find a way around
it.
"Dim oOutlookApp As Outlook.Application" generates the following error:
Compile Error: User-defined type not defined

I don't know if and when I get around this there will be more errors or not...

My goal is to send out 200 emails to 200 different addresses. The email
text message and subject line are the same, but each email has a unique
attachment. The attachments are all updated on a regular basis and are sent
out via email after each update.

Any help is greatly appreciated.
 
S

Sue Mosher [MVP]

It's a simple error with a simple fix: Use the Tools | References command to
add a reference to the Microsoft Outlook library and any other non-Word
library that your code might nteed.
 
K

KimS

Thanks for the quick response. I probably should have mentioned a couple of
other items: 1) I have MS Office 2003 and VBA version 6.5. 2) I am not well
versed in VBA, though I have developed a few macros to make life easier.

When I go to references, all I can do is either select or disselect objects.
There is no option for modification. I do have the Microsoft Office 11.0
Object Library selected.

Is there an easier way to link emails with unique files for a large emailing?
 
S

Sue Mosher [MVP]

Who said anything about modification? Choose Tools | References, find the
Microsoft Outlook library and select it.

If you don't want to write code, I'm sure the http://www.slipstick.com site
can point you to tools you can download to do that kind of mailing.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
K

KimS

Thank you Sue. I am not sure what is different now than before - the Outlook
objects were selected, but I started over this time.

It appears to run through the paces, now I just need to figure out why no
emails were received by my test subjects.

Thank you for the help - it is really appreciated. I'll be tweaking my
program now as needed.
 
T

Tirath

KimS said:
Thank you Sue. I am not sure what is different now than before - the Outlook
objects were selected, but I started over this time.

It appears to run through the paces, now I just need to figure out why no
emails were received by my test subjects.

Thank you for the help - it is really appreciated. I'll be tweaking my
program now as needed.
 
T

Tirath

Sue,

i am facing the same problem.

Microsoft Office 11.0 Object Library is already selected, but it doesn't
work.....


I am running the following code.


Sub emailmergewithattachments()

Dim Source As Document, Maillist As Document, TempDoc As Document
Dim Datarange As Range
Dim i As Long, j As Long
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim mysubject As String, message As String, title As String

Set Source = ActiveDocument

' Check if Outlook is running. If it is not, start Outlook
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

' Open the catalog mailmerge document
With Dialogs(wdDialogFileOpen)
.Show
End With
Set Maillist = ActiveDocument

' Show an input box asking the user for the subject to be inserted into the
email messages
message = "Enter the subject to be used for each email message." ' Set
prompt.
title = " Email Subject Input" ' Set title.
' Display message, title
mysubject = InputBox(message, title)

' Iterate through the Sections of the Source document and the rows of the
catalog mailmerge document,
' extracting the information to be included in each email.
For j = 1 To Source.Sections.Count - 1
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.Body = Source.Sections(j).Range.Text
Set Datarange = Maillist.Tables(1).Cell(j, 1).Range
Datarange.End = Datarange.End - 1
.To = Datarange
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
.Send
End With
Set oItem = Nothing
Next j
Maillist.Close wdDoNotSaveChanges

' Close Outlook if it was started by this macro.
If bStarted Then
oOutlookApp.Quit
End If

MsgBox Source.Sections.Count - 1 & " messages have been sent."

'Clean up
Set oOutlookApp = Nothing

End Sub
 
S

Sue Mosher [MVP]

Did you follow my advice to Kim and add a reference to the Microsoft Outlook
11.0 library? If so, then you need to explain exactly what isn't working in
your particular case.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
V

Virginia Arenas

I also got a problem with this process.

My emails are not send. I run the macro, choose the document and get a note that says "0 messages sent". I hope somebody can help me.



Sue Mosher [MVP] wrote:

Did you follow my advice to Kim and add a reference to the Microsoft Outlook11.
16-sep-09

Did you follow my advice to Kim and add a reference to the Microsoft Outloo
11.0 library? If so, then you need to explain exactly what is not working i
your particular case
-
Sue Mosher, Outlook MV
Author of Microsoft Outlook 2007 Programming
Jumpstart for Power Users and Administrator
http://www.outlookcode.com/article.aspx?id=54

Previous Posts In This Thread:

On jueves, 10 de septiembre de 2009 17:50
KimS wrote:

Mail Merge to email with attachments
I found instructions for using mail merge in Word to send multiple email
with attachments ("Mail Merge to E-mail with Attachments" by Doug Robbins)
The macro generates an error and I have not been able to find a way aroun
it
"Dim oOutlookApp As Outlook.Application" generates the following error
Compile Error: User-defined type not define

I do not know if and when I get around this there will be more errors or not..

My goal is to send out 200 emails to 200 different addresses. The emai
text message and subject line are the same, but each email has a uniqu
attachment. The attachments are all updated on a regular basis and are sen
out via email after each update

Any help is greatly appreciated.

On jueves, 10 de septiembre de 2009 18:35
Sue Mosher [MVP] wrote:

it is a simple error with a simple fix: Use the Tools | References command
it is a simple error with a simple fix: Use the Tools | References command t
add a reference to the Microsoft Outlook library and any other non-Wor
library that your code might nteed

-
Sue Mosher, Outlook MV
Author of Microsoft Outlook 2007 Programming
Jumpstart for Power Users and Administrator
http://www.outlookcode.com/article.aspx?id=54

On viernes, 11 de septiembre de 2009 11:16
KimS wrote:

Thanks for the quick response.
Thanks for the quick response. I probably should have mentioned a couple o
other items: 1) I have MS Office 2003 and VBA version 6.5. 2) I am not wel
versed in VBA, though I have developed a few macros to make life easier

When I go to references, all I can do is either select or disselect objects
There is no option for modification. I do have the Microsoft Office 11.
Object Library selected

Is there an easier way to link emails with unique files for a large emailing

:

On viernes, 11 de septiembre de 2009 15:03
Sue Mosher [MVP] wrote:

Who said anything about modification?
Who said anything about modification? Choose Tools | References, find th
Microsoft Outlook library and select it

If you do not want to write code, I am sure the http://www.slipstick.com sit
can point you to tools you can download to do that kind of mailing

-
Sue Mosher, Outlook MV
Author of Microsoft Outlook 2007 Programming
Jumpstart for Power Users and Administrator
http://www.outlookcode.com/article.aspx?id=54

On viernes, 11 de septiembre de 2009 16:03
KimS wrote:

Thank you Sue.
Thank you Sue. I am not sure what is different now than before - the Outloo
objects were selected, but I started over this time

It appears to run through the paces, now I just need to figure out why n
emails were received by my test subjects

Thank you for the help - it is really appreciated. I will be tweaking m
program now as needed

:

On mi?rcoles, 16 de septiembre de 2009 9:56
Tirath wrote:

:
:

On mi?rcoles, 16 de septiembre de 2009 10:00
Tirath wrote:

Sue,i am facing the same problem.Microsoft Office 11.
Sue

i am facing the same problem

Microsoft Office 11.0 Object Library is already selected, but it does no
work....

I am running the following code

Sub emailmergewithattachments(

Dim Source As Document, Maillist As Document, TempDoc As Documen
Dim Datarange As Rang
Dim i As Long, j As Lon
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim mysubject As String, message As String, title As String

Set Source = ActiveDocument

' Check if Outlook is running. If it is not, start Outlook
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

' Open the catalog mailmerge document
With Dialogs(wdDialogFileOpen)
..Show
End With
Set Maillist = ActiveDocument

' Show an input box asking the user for the subject to be inserted into the
email messages
message = "Enter the subject to be used for each email message." ' Set
prompt.
title = " Email Subject Input" ' Set title.
' Display message, title
mysubject = InputBox(message, title)

' Iterate through the Sections of the Source document and the rows of the
catalog mailmerge document,
' extracting the information to be included in each email.
For j = 1 To Source.Sections.Count - 1
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
..Subject = mysubject
..Body = Source.Sections(j).Range.Text
Set Datarange = Maillist.Tables(1).Cell(j, 1).Range
Datarange.End = Datarange.End - 1
..To = Datarange
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
..Send
End With
Set oItem = Nothing
Next j
Maillist.Close wdDoNotSaveChanges

' Close Outlook if it was started by this macro.
If bStarted Then
oOutlookApp.Quit
End If

MsgBox Source.Sections.Count - 1 & " messages have been sent."

'Clean up
Set oOutlookApp = Nothing

End Sub





















:

On mi?rcoles, 16 de septiembre de 2009 10:14
Sue Mosher [MVP] wrote:

Did you follow my advice to Kim and add a reference to the Microsoft Outlook11.
Did you follow my advice to Kim and add a reference to the Microsoft Outlook
11.0 library? If so, then you need to explain exactly what is not working in
your particular case.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

EggHeadCafe - Software Developer Portal of Choice
Team Development Concepts with Visual Studio.NET
http://www.eggheadcafe.com/tutorial...d-33e808ca2492/team-development-concepts.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top