Hi Team,
Am new to this group. I have written a code using VBA to send a mail from excel column values which has email-id's. I have send a document as a body message to that mail. Its working fine that calls the document and send mail to respective email-id's. But am trying to send some text in the body of the mail. Here is the sample code which i have used to send
`Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Outlook.MailItem
Dim ID As String
Dim blnWeOpenedWord As Boolean
Dim i As Integer
Dim EmailTo As String
Dim msg As String
Dim username As String
On Error Resume Next
i = 2
Do
EmailTo = ThisWorkbook.Sheets("Master Sheet").Cells(i, 2).Value
username = ThisWorkbook.Sheets("Master Sheet").Cells(i, 3).Value
msg = "Dear " & username & ","
Set wd = GetObject(, "Word.Application")
Set itm = OutApp.CreateItem(0)
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(Filename:="E:\Excel\References\sampleDoc.docx", ReadOnly:=True)
Set itm = doc.MailEnvelope.Item & msg
With itm
.To = EmailTo
.Subject = msg
'.Body = "Dear " & username
.Send
ThisWorkbook.Sheets("Master Sheet").Cells(i, "H").Value = "Sent"
'On Error GoTo 0
End With
i = i + 1
Loop Until ThisWorkbook.Sheets("Master Sheet").Cells(i, "B").Value = ""
If blnWeOpenedWord Then
wd.Quit
End If
doc.Close wdDoNotSaveChanges
Set OutMail = Nothing
Set OutApp = Nothing
Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub
`
In subject am able to see Dear username but not in the body of the text.
It looks like you're new here. If you want to get involved, click one of these buttons!