Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
cathyb56 cathyb56 is offline
external usenet poster
 
Posts: 1
Default Macro Modification for MailMerge

Hi. I hope you can help. I'm having a weird problem involving Word,
MailMerge via a macro.

Currently I have a document that has a macro in it that opens an Access
database--inserts customer information and prints out individualized letters.
I would like to modify the macro so that the letters merge to eMail. I can
do this manually, but when I try to modify the macro, I get run-time errors.

Ideally, it would be great if the letters would appear in the body of the
message. However, I've found that it shows modifications to the letters. It
seems to work better as an attachment.

I would appreciate any help you can give me with this problem.

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 Macro Modification for MailMerge

You would have to show us the code for the Macro (as you have modified it)
if you want help with it.

The code that you would need however is contained in the article "Mail Merge
to E-mail with Attachments" at:

http://word.mvps.org/FAQs/MailMerge/...ttachments.htm

If however, you want the message sent in HTML Format, replace the code in
that article with:

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
Source.Sections(j).Range.Copy
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.BodyFormat = olFormatHTML
.Display
Set objDoc = .GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Paste
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

There may however be better ways of doing what you want. Perhaps doing it
completely in Access would be better.

--
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, originally posted via msnews.microsoft.com
"cathyb56" wrote in message
...
Hi. I hope you can help. I'm having a weird problem involving Word,
MailMerge via a macro.

Currently I have a document that has a macro in it that opens an Access
database--inserts customer information and prints out individualized
letters.
I would like to modify the macro so that the letters merge to eMail. I
can
do this manually, but when I try to modify the macro, I get run-time
errors.

Ideally, it would be great if the letters would appear in the body of the
message. However, I've found that it shows modifications to the letters.
It
seems to work better as an attachment.

I would appreciate any help you can give me with this problem.

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
Mailmerge in a macro dave Mailmerge 2 May 14th 07 06:48 PM
Mailmerge and Macro uriahheep Mailmerge 1 December 7th 06 03:56 PM
MailMerge Macro HELP Dirdata via OfficeKB.com Microsoft Word Help 1 October 6th 06 11:14 AM
Word mailmerge to PDF macro Martin Mailmerge 2 April 13th 06 06:31 AM
Mailmerge by macro J.Reynolds Mailmerge 5 June 17th 05 09:36 PM


All times are GMT +1. The time now is 03:43 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"