PDA

View Full Version : [SOLVED] Run Outlook from Excel



CCkfm2000
06-17-2005, 09:41 AM
: pray2: hi all..
i've found some vba code to send email's from excel ( see code below ).
what i need is to run outlook before the code or check if outlook is already running. then run the code.

many thanks :friends:


Option Explicit

Sub Mail_ActiveSheet_Outlook()
'You must add a reference to the Microsoft outlook Library
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim WB As Workbook
Dim strdate As String
strdate = Format(Now, "dd-mm-yy h-mm-ss")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set WB = ActiveWorkbook
With WB
.SaveAs "Part Of ..." & ThisWorkbook.Name _
& " " & strdate & ".xls"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "a_user@anywhere.com"
'.CC = ""
'.BCC = ""
.Subject = "stats 2005"
.Body = "See Attached File Please...."
.Attachments.Add WB.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Zack Barresse
06-17-2005, 09:49 AM
Hi there,

If you're only looking to check if outlook is open or not, maybe you can use something like this ...


Sub CheckOLopen()
Dim AppOutLook As Object
On Error Resume Next
Set AppOutLook = GetObject(, "Outlook.Application")
On Error Goto 0
If AppOutLook Is Nothing Then
MsgBox "Need to open Outlook."
Else
MsgBox "Outlook is open, so no need to open it."
End If
End Sub

CCkfm2000
06-17-2005, 10:04 AM
thanks for the quick reply, just had a go with the code and keeps saying "Outlook is open, so no need to open it." when it's not!.

CCkfm2000
06-20-2005, 03:18 AM
sorry my mistake it work. thanks