Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 01-31-2012, 04:14 AM
macropod's Avatar
macropod macropod is offline How do I E.mail documents Windows 7 64bit How do I E.mail documents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
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 tweacle,

re:
Quote:
im trying to get it to work if outlook is already open
From looking at your code, that's exactly what it should already do. Can you provide more details on the issues you're having? Do you have a reference to the Outlook Object Library set?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



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 09:10 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