How to format the outlook body messages - VBA with MS Word -High level automation

Опубликовано: 19 Октябрь 2024
на канале: Ajay Kumar
2,471
46

here is a code for this project with the help of which we can format the outlook body in any way we want. If you want to support this channel you can give donation on www.excelvbalover.com and click on donation link.


Dim o As Outlook.Application
Dim omail As Outlook.MailItem
Dim wd As Word.Application
Sub FirstStagePreview()


Application.DisplayAlerts = False
Set wd = New Word.Application
wd.Visible = True


Set o = New Outlook.Application


Dim ws1 As Worksheet
Set ws1 = Sheets("Firstlevel")


Dim INDEX As Long, lrow As Long
lrow = Sheets("Send emails").Range("a100000").End(xlUp).Row


Dim STORE, MYCELL As Range


Dim doc As Word.Document, Rng As Range
Dim insp As Outlook.Inspector


'..................................................................................................................................


Set Rng = ws1.Range("R3:R" & ws1.Range("R100000").End(xlUp).Row + 10)
Rng.Copy
Set doc = wd.Documents.Add


doc.Content.Paste
doc.Content.Select
doc.Content.Copy


Application.Wait Now() + TimeSerial(0, 0, 1)


'.......Email starts.................................................................


With omail


Set omail = o.CreateItem(olMailItem)
Set insp = omail.GetInspector

omail.Subject = Range("R2")

Set doc = insp.WordEditor
doc.Content.Paste
omail.Display




End With


Set doc = wd.ActiveDocument
doc.Close (False)
wd.Quit (False)


Set insp = Nothing
Set omail = Nothing
Set o = Nothing


End Sub