Solved

Outlook 2007 sending Word 2003 document in email body

Posted on 2009-07-12
4
497 Views
Last Modified: 2012-05-07
hi all,

I am trying to create the macro in Word 2003 which allows you to create an email in Outlook 2007 and put the Word document in the body of the email.

I have seen the script here and got it working:

http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_24428085.html

However the script just generates an email with the default to, subject etc in it and sends it immediately.  I need the script to pop up the Outlook email so i can enter the to adress, subject etc and preview the body text.

I have absolutely no VB experience or knowledge and don't have a clue how I can make this happen.  Could anyone help?

nathan
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
    .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

Open in new window

0
Comment
Question by:natrat22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 500 total points
ID: 24840533
Instead of the .Send line change it to .Display and I also added an input box for the recipient.

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)
 
Recipient = InputBox("Please enter recipient(s) email address(es).")
 
With oItem
    'Set the recipient for the new email
   .To = Recipient
    '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
    '.Send
    .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

Open in new window

0
 
LVL 1

Author Comment

by:natrat22
ID: 24855224
Jorzech, you rock.  thanks, that worked perfectly.
0
 
LVL 1

Author Closing Comment

by:natrat22
ID: 31602674
much appreciated.
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24860686
Terrific!  I am so pleased I was able to help you.  Thanks much natrat22 :)

Joanne Orzech
MS Word MVP
EE Zone Advisor
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question