Copy Text from Word Doc into E-mail message

  • Thread starter Thread starter gumby
  • Start date Start date
G

gumby

I have the following macro to send out an e-mail with an attachment.

Sub SendMailMorning()
Set objMail = Application.CreateItem(0)
With objMail
.Subject = "Subject"
.To = "address"
.CC = "address"
.BCC = "address"
.Attachments.Add "c:\temp\File.rtf"
.Send
End With
End Sub

However I would like to be able to take the text out of the word doc
and place it into the message of the e-mail instead of attaching it. Is
this possible?

Thanks -
 
Thanks - I will check it out. I want all text and it is the word doc
that I am currently attaching. or .rtf.

David
 
If you want all the text, you can use the "Office envelope" feature. This code starts Word if it isn't already running, opens your document, creates a message from it, saves and sends the message, then closes Word if appropriate:

Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(FileName:="c:\temp\File.rtf", ReadOnly:=True)
Set itm = doc.MailEnvelope.Item
With itm
.To = "Address"
.Subject = "Subject"
.Save
ID = .EntryID
End With
Set itm = Nothing

Set itm = Application.Session.GetItemFromID(ID)
itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub

Note that this is Outlook VBA code and requires a reference to the Microsoft Word library in Tools | References.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Thanks, it worked like a charm. Would this method be the same for other
applications?

David
 
Excel also supports this technique, so you could rewrite it to use Excel objects instead of Word.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Going back to my attachment code at the top. How would I attach more
than one file?

Thanks,
David
 
If what you have now is:

.Attachments.Add "c:\temp\File.rtf"

then to add another attached file, you'd repeat that statement:

.Attachments.Add "c:\temp\File2.rtf"

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


gumby said:
Going back to my attachment code at the top. How would I attach more
than one file?

Thanks,
David

If you want all the text, you can use the "Office envelope" feature. This code starts Word if it isn't already running, opens your document, creates a message from it, saves and sends the message, then closes Word if appropriate:

Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(FileName:="c:\temp\File.rtf", ReadOnly:=True)
Set itm = doc.MailEnvelope.Item
With itm
.To = "Address"
.Subject = "Subject"
.Save
ID = .EntryID
End With
Set itm = Nothing

Set itm = Application.Session.GetItemFromID(ID)
itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub

Note that this is Outlook VBA code and requires a reference to the Microsoft Word library in Tools | References.

gumby said:
Thanks - I will check it out. I want all text and it is the word doc
that I am currently attaching. or .rtf.

David

Sue Mosher [MVP-Outlook] wrote:
What Word doc? All the text or just some?

I have the following macro to send out an e-mail with an attachment.

Sub SendMailMorning()
Set objMail = Application.CreateItem(0)
With objMail
.Subject = "Subject"
.To = "address"
.CC = "address"
.BCC = "address"
.Attachments.Add "c:\temp\File.rtf"
.Send
End With
End Sub

However I would like to be able to take the text out of the word doc
and place it into the message of the e-mail instead of attaching it. Is
this possible?
 
I thought I had tried that before. It worked and Thank you tons.

David said:
If what you have now is:

.Attachments.Add "c:\temp\File.rtf"

then to add another attached file, you'd repeat that statement:

.Attachments.Add "c:\temp\File2.rtf"

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


gumby said:
Going back to my attachment code at the top. How would I attach more
than one file?

Thanks,
David

If you want all the text, you can use the "Office envelope" feature. This code starts Word if it isn't already running, opens your document, creates a message from it, saves and sends the message, then closes Word if appropriate:

Sub SendDocAsMsg()
Dim wd As Word.Application
Dim doc As Word.Document
Dim itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(FileName:="c:\temp\File.rtf", ReadOnly:=True)
Set itm = doc.MailEnvelope.Item
With itm
.To = "Address"
.Subject = "Subject"
.Save
ID = .EntryID
End With
Set itm = Nothing

Set itm = Application.Session.GetItemFromID(ID)
itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If

Set doc = Nothing
Set itm = Nothing
Set wd = Nothing
End Sub

Note that this is Outlook VBA code and requires a reference to the Microsoft Word library in Tools | References.

Thanks - I will check it out. I want all text and it is the word doc
that I am currently attaching. or .rtf.

David

Sue Mosher [MVP-Outlook] wrote:
What Word doc? All the text or just some?

I have the following macro to send out an e-mail with an attachment.

Sub SendMailMorning()
Set objMail = Application.CreateItem(0)
With objMail
.Subject = "Subject"
.To = "address"
.CC = "address"
.BCC = "address"
.Attachments.Add "c:\temp\File.rtf"
.Send
End With
End Sub

However I would like to be able to take the text out of the word doc
and place it into the message of the e-mail instead of attaching it. Is
this possible?
 
Back
Top