Hi Guys,
I am trying to write an VBA Code that would help creating Outlook Email message with To, CC and Subject fields.
However, the body, I need to be read from Word File saved in my computer drive.
Here is what I have reached so far, yet, it works only for creating the email message with the needed field except for the body part.
Sub Email_Template1()
Dim oMailItem As Object
Dim oOLapp As Object
Dim Word As Object
Dim doc As Object
Dim MsgTxt As String
Set oOLapp = CreateObject("Outlook.Application")
Set oMailItem = oOLapp.CreateItem(0)
With oMailItem
.To = "Email"
.CC = "Email"
.Subject = "Needed Confirmation"
.Display
End With
Set Word = CreateObject("word.application")
Set doc = Word.Documents.Open _
(FileName:="G:\Customer Services\File Plan\Magdoulin\To be deleted 1.docx", ReadOnly:=True)
'Pulls text from file for message body
MsgTxt = doc.Range(Start:=doc.Paragraphs(1).Range.Start, _
End:=doc.Paragraphs(doc.Paragraphs.Count).Range.End)
Set oOLapp = Nothing
Set oMailItem = Nothing
End Sub
I am trying to write an VBA Code that would help creating Outlook Email message with To, CC and Subject fields.
However, the body, I need to be read from Word File saved in my computer drive.
Here is what I have reached so far, yet, it works only for creating the email message with the needed field except for the body part.
Sub Email_Template1()
Dim oMailItem As Object
Dim oOLapp As Object
Dim Word As Object
Dim doc As Object
Dim MsgTxt As String
Set oOLapp = CreateObject("Outlook.Application")
Set oMailItem = oOLapp.CreateItem(0)
With oMailItem
.To = "Email"
.CC = "Email"
.Subject = "Needed Confirmation"
.Display
End With
Set Word = CreateObject("word.application")
Set doc = Word.Documents.Open _
(FileName:="G:\Customer Services\File Plan\Magdoulin\To be deleted 1.docx", ReadOnly:=True)
'Pulls text from file for message body
MsgTxt = doc.Range(Start:=doc.Paragraphs(1).Range.Start, _
End:=doc.Paragraphs(doc.Paragraphs.Count).Range.End)
Set oOLapp = Nothing
Set oMailItem = Nothing
End Sub