Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / July 2006

Tip: Looking for answers? Try searching our database.

"Mail Merge to E-Mail with Attachments" questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 03 Jul 2006 20:59 GMT
I am using the "Mail Merge to E-Mail with Attachments" macro witout success.  
The macro appears to run three times (the number of e-mail addresses I am
using to test), but the test e-mail accounts do not receive the message.  
Furthermore, I do NOT have messages in mu Outlook Outbox or sent messages
folder.

Did I inadvertently alter the macro?  For the life of me, I can't find the
typo! Here 'tis:

Sub EMailMergeWithAttachments()

Dim Source As Document
Dim MailList As Document
Dim DataRange As Range
Dim Counter As Integer
Dim i As Integer
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim MySubject As String
Dim Message As String
Dim Title As String

Set Source = ActiveDocument

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

'Open the Catalog Mail Merge Document
With Dialogs(wdDialogFileOpen)
   .Show
End With
Set MailList = ActiveDocument

'Show an Input box for the e-mail subject line
Message = "Enter the subject to be used for each e-mail message"  'Set the
dialog box prompt
Title = "E-Mail Subject Line:"
MySubject = InputBox(Message, Title)

'Iterate through the rows of the catalog mailmerge,
'extracting the info for the message

Counter = 1
While Counter <= MailList.Tables(1).Rows.Count
   Source.Sections.First.Range.Cut
   Documents.Add
   Selection.Paste
   Set oItem = oOutlookApp.CreateItem(olMailItem)
   With oItem
       .Subject = MySubject
       .Body = ActiveDocument.Content
       Set DataRange = MailList.Tables(1).Cell(Counter, 1).Range
       DataRange.End = DataRange.End - 1
       .to = DataRange
       For i = 2 To MailList.Tables(1).Columns.Count
           Set DataRange = MailList.Tables(1).Cell(Counter, i).Range
           DataRange.End = DataRange.End - 1
           .Attachments.Add Trim(DataRange.Text), olByValue, 1
       Next i
       .Send
   End With
   Set oItem = Nothng
   ActiveDocument.Close wdDoNotSaveChanges
   Counter = Counter + 1
Wend

'Close Outlook if started by the macro
If bStarted Then
   oOutlookApp.Quit
End If

'Clean Up
Set oOutlookApp = Nothing
Source.Close wdDoNotSaveChanges
MailList.Close wdDoNotSaveChanges

End Sub

*****
Any help is appreciated.  Thanks!
Doug Robbins - Word MVP - 03 Jul 2006 21:40 GMT
Looks OK.

Try sticking a

MsgBox DataRange

before

.to = DataRange

and make sure that it is being populated with a valid email address.
Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I am using the "Mail Merge to E-Mail with Attachments" macro witout
>success.
[quoted text clipped - 82 lines]
> *****
> Any help is appreciated.  Thanks!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.