LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Excel VBA coding - Outlook and Shut down issue

Could someone please help me with the folowing code? It is called
from a button and attaches a file to an email.

It works fine except two things.

1 It will get an error on Set EmailItem =OL.CreateItem(OLMailItem)
if outlook is not already open. How can I change it so outlook does
not have to be already open?

2 Application.Quit closes the current workbook, but does not close
excel completely. I need it to shut down completely.


Sub Button6_Click()
Dim OL As Object
Dim EmailItem As Object
Dim FileName As String

'Shut Down Screen and Events
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True

' Setup OutLook Object
Application.EnableEvents = True
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(OLMailItem)
FileName = "Attachment.xls"

' Load Email
ActiveWorkbook.SaveAs "C:\" & FileName
On Error Resume Next
With EmailItem
.Subject = ActiveSheet.Name
.Body = ActiveSheet.Name
.Importance = 2 ' 0 = Low 1 = Normal 2 = High
.Attachments.Add "C:\" & FileName
.Display ' Load The Email
End With

'Shut down Excel
ActiveWorkbook.Close False
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True

Kill "C:\" & FileName
Set OL = Nothing
Set EmailItem = Nothing
Application.Quit
End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding issue with Excel 2003 Neil Holden Excel Discussion (Misc queries) 1 February 18th 10 04:38 PM
Excel 2003 coding issue Neil Holden Excel Discussion (Misc queries) 0 February 16th 10 09:18 AM
outlook shut off, Is all info lost forever bobo Excel Discussion (Misc queries) 0 March 13th 07 01:34 AM
Excel VBA coding - Outlook and Shut down issue [email protected] Excel Worksheet Functions 0 October 1st 06 06:29 PM
What 's wrong with the coding? -- about using outlook to send attachment in excel Terry Excel Programming 1 February 5th 04 10:31 PM


All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"