![]() |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
hi tweacle,
re: Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| 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 |
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 |