View Single Post
  #7  
Old September 16th 09, 03:00 PM posted to microsoft.public.outlook.program_vba
Tirath
external usenet poster
 
Posts: 2
Default Mail Merge to email with attachments

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





















"KimS" wrote:

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.

"Sue Mosher [MVP]" wrote:

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


"KimS" wrote in message
...
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?

"Sue Mosher [MVP]" wrote:

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.

"KimS" wrote in message
...
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.






Ads