![]() |
|
#1
|
|||
|
|||
|
Hi all,
I'm new to Word Vba and I'm trying to do a Macro to send various mails with attachment by Merge Mail tool help. I copy some indications from various webs but I cannot find a solution to my problem The macro is working, but it send the mail without format. I'd like to send the mail in the same format as it appear in word. I'm using this code 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
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
With Dialogs(wdDialogFileOpen)
.Show
End With
Set Maillist = ActiveDocument
message = "Enter the subject to be used for each email message."
title = " Email Subject Input"
mysubject = InputBox(message, title)
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
.BCC= "amentinho@example.com"
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
If bStarted Then
oOutlookApp.Quit
End If
MsgBox Source.Sections.Count - 1 & " messages have been sent."
Set oOutlookApp = Nothing
End Sub
Any help would be really appreciate. Thanks |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Mail Merge Format random 0s
|
lmoir87 | Mail Merge | 2 | 07-31-2014 03:45 AM |
Change Mail Merge Date Format from US to UK
|
Evanaught | Mail Merge | 1 | 09-29-2013 08:02 PM |
Issue with date format in mail merge document
|
walshjod | Mail Merge | 4 | 11-28-2012 04:46 AM |
Mail merge will not format date field generated by Excel IF statement
|
borntorun75 | Mail Merge | 3 | 12-16-2011 06:28 AM |
Correct Format needed
|
TonyB | Mail Merge | 3 | 05-03-2011 01:10 AM |