Thread: [Solved] How do I E.mail documents
View Single Post
 
Old 01-10-2012, 03:52 AM
tweacle tweacle is offline Windows XP Office 2007
Novice
 
Join Date: Jan 2012
Posts: 1
tweacle is on a distinguished road
Default How do I E.mail documents

Hi there

I have the follwoing macro given but im trying to get it to work if outlook is already open. Can anyone help.

Thanks


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

Last edited by macropod; 01-31-2012 at 04:10 AM. Reason: Added code tags
Reply With Quote