Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Dan Dan is offline
external usenet poster
 
Posts: 135
Default "Mail Merge to E-Mail with Attachments" questions

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!
  #2   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 "Mail Merge to E-Mail with Attachments" questions

Looks OK.

Try sticking a

MsgBox DataRange

before

..to = DataRange

and make sure that it is being populated with a valid email address.
--
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

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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge Word 2003 Issue S.Nicks Mailmerge 5 February 20th 09 01:55 AM
Problem: Mail Merge with Fill-ins asks for fill-in value for every label, not just once Rhino Mailmerge 3 June 17th 06 05:35 AM
Mail Merge can't find data source in Office XP...but it could in 2000! [email protected] Mailmerge 4 June 7th 06 03:15 PM
Mail Merge Losing Data Scott May Mailmerge 1 November 1st 05 11:03 PM
How do I make footnote numners static in a mail merge document? Heather Mailmerge 5 October 14th 05 04:59 AM


All times are GMT +1. The time now is 01:30 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"