Formatting an email sent from Word through Outlook

M

Matt

Hello,
Ok so I have a word document that I want to send in the body of an email
rather then as an attachment. But when it is sent it looks nothing like how
it looks in the word doc. In the doc I have graphs, excel files and other
types of charts. When the message is recieved it is just text. Any help would
be much appreciated.

---------------------code-------------------------------
Private Sub CommandButton1_Click()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
..To = "(e-mail address removed)"
..Subject = "Daily Operational Report"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
..Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue,
DisplayName:="Document as attachment"
..Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
----------------------------------------------------------------
 
J

Jean-Guy Marcil

Matt said:
Hello,
Ok so I have a word document that I want to send in the body of an email
rather then as an attachment. But when it is sent it looks nothing like how
it looks in the word doc. In the doc I have graphs, excel files and other
types of charts. When the message is recieved it is just text. Any help would
be much appreciated.

I am not sure I follow, the code you posted sends the document as an
attachment, not as the body...

Unfortunately, if the people you send this message to have set their eMail
browser to text only (No HTML), then there is nothing you can do.

Even if they haven't, Word-generated HTML can be rendered in many
unpredictable ways, depending on the eMail browser they use. Even more so if
you have embeded OLE objects in your Word document...

Better send a PDF image or an attachment.
 
M

Matt

Oh, I inserted the wrong code lol, heres the real code. So there is really no
command that inserts the body of the document into an email as is. Though I
can copy and paste the word document into the body of the email, but what I'm
really going for is as much automation as possible.
---------------------------------------------------
Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient for the new email
..To = "(e-mail address removed)"
'Set the recipient for a copy
..CC = "(e-mail address removed)"
'Set the subject
..Subject = "New subject"
'The content of the document is used as the body for the email
..Body = ActiveDocument.Content
..Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
-----------------------------------------------------
 
J

Jean-Guy Marcil

Matt said:
Oh, I inserted the wrong code lol, heres the real code. So there is really no
command that inserts the body of the document into an email as is. Though I
can copy and paste the word document into the body of the email, but what I'm
really going for is as much automation as possible.

You can try with
ActiveDocument.Content.FormattedText
instead of
ActiveDocument.Content

But, again, there are no guarantees that the recepient will see the content
as you see it in Word (Whether you manually Copy/Paste or automate this
part), even if HTML (or Rich Text as it is some time called in some eMail
applications) is on.
 
M

Matt

So I tried adding the .Formattedtext and it really didnt change the look of
it at all. I remember reading a post somewhat the same as what I am trying to
do and they had given them some code, but what the code did was take the
selection and put it in the body and I think that seemed to work but it didnt
work right everytime. So I guess your right and I am just gona have to insert
it as an attachment. Thanks for your help and let me know if you are able to
come up with anything else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top