Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2011, 05:21 AM
aonzo aonzo is offline Sending word document via outlook Windows 7 64bit Sending word document via outlook Office 2010 64bit
Novice
Sending word document via outlook
 
Join Date: Dec 2011
Posts: 2
aonzo is on a distinguished road
Default Sending word document via outlook

Hi

I've found the below code and wanted to know if there's a way too keep the format i have in my word document to the email sent out via outlook? At the moment, it turns the text into plain text(not keeping the format on word)

Is there a way to keep the format?


Aonzo



Code:
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 = "recipient@mail.com"
    'Set the recipient for a copy
    .CC = "recipient2@mail.com"
    'Set the subject
    .Subject = "New subject"
    'The content of the document is used as the body for the email
    .Body = ActiveDocument.Content
    .Display
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
Reply With Quote
  #2  
Old 12-21-2011, 07:17 PM
macropod's Avatar
macropod macropod is offline Sending word document via outlook Windows 7 64bit Sending word document via outlook Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Aonzo,

You might find the discussion here useful: http://www.vbaexpress.com/forum/showthread.php?t=20158
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-03-2012, 08:06 AM
aonzo aonzo is offline Sending word document via outlook Windows 7 64bit Sending word document via outlook Office 2010 32bit
Novice
Sending word document via outlook
 
Join Date: Dec 2011
Posts: 2
aonzo is on a distinguished road
Default

thanks, i found some new code that did the job.

Please find below, in case someone was interested.

Code:
Sub FillOutlookBody()
    ActiveDocument.Content.Copy
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objInspector As Outlook.Inspector
    Dim objDoc As Word.Document
    Set objOutlook = CreateObject("Outlook.Application")
     
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
         'Set the recipient for the new email
   .To = "fake@email.com"
    'Set the recipient for a copy
    .CC = "fake@email.com"
    'Set the subject
    .Subject = "subject"
    'The content of the document is used as the body for the email
    .Body = ActiveDocument.Content
    .Display
    End With
    Set objInspector = objOutlook.ActiveInspector
    If Not objInspector Is Nothing And objInspector.EditorType = olEditorWord Then
        Set objDoc = objInspector.WordEditor
        objDoc.Range.Paste
    End If
    Set objDoc = Nothing
    Set objOutlookMsg = Nothing
    Set objInspector = Nothing
    Set objOutlook = Nothing
End Sub
Reply With Quote
Reply

Tags
format, outlook 2010, word 2010



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending word document via outlook Outlook sending problem Abbottking Outlook 2 10-03-2011 08:44 AM
Word document has outlook send message fields at top yancyxc Word 0 06-21-2011 08:55 AM
Sending word document via outlook Outlook not sending manual emails- ruggb Outlook 1 10-20-2010 12:29 PM
Outlook sending multiple emails Shawn76 Outlook 0 08-07-2010 09:10 AM
Sending word document via outlook Convert word document to JPEG. The word document may contain headerfooters vijayaram Word 1 12-30-2009 08:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft