Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-10-2015, 02:16 AM
amentinho amentinho is offline Mail Merge with correct format Windows 8 Mail Merge with correct format Office 2013
Novice
Mail Merge with correct format
 
Join Date: Mar 2015
Posts: 4
amentinho is on a distinguished road
Default Mail Merge with correct format

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
How can I use this macro manteining the original word file format?

Any help would be really appreciate.

Thanks
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge with correct format Mail Merge Format random 0s lmoir87 Mail Merge 2 07-31-2014 03:45 AM
Mail Merge with correct format Change Mail Merge Date Format from US to UK Evanaught Mail Merge 1 09-29-2013 08:02 PM
Mail Merge with correct format Issue with date format in mail merge document walshjod Mail Merge 4 11-28-2012 04:46 AM
Mail Merge with correct format Mail merge will not format date field generated by Excel IF statement borntorun75 Mail Merge 3 12-16-2011 06:28 AM
Mail Merge with correct format Correct Format needed TonyB Mail Merge 3 05-03-2011 01:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft