Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-10-2012, 03:52 AM
tweacle tweacle is offline How do I E.mail documents Windows XP How do I E.mail documents Office 2007
Novice
How do I E.mail documents
 
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not receive mail when using group mail in Microsoft Outlook 2007 nhat2nhat2 Outlook 0 10-09-2011 08:28 AM
How do I E.mail documents Saving INDV mail merges During the mail merge sedain121 Mail Merge 2 10-04-2011 07:52 PM
utlook 2010 is not receiving G-mail (IMAP) E-mail CGChicago Outlook 0 12-28-2010 03:49 PM
Error: general mail failure. Quit excel restart mail system MitchellDM Outlook 1 12-19-2008 02:05 AM
Add date and time stamp to new mail and incoming mail cadsmarter Outlook 0 02-02-2006 08:50 AM

Other Forums: Access Forums

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


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