JimJohnson
New Member
- Joined
- Apr 29, 2008
- Messages
- 36
The first two parts of this macro work just fine, it's the closing part of it which doesn't work. The strange thing is, if I isolate the close part of the macro and run it as it's own macro, it will work. However, it will not work as part of a larger macro, or even if called from a higher macro which contained the open portion. Here is my code:
If anyone can explain what I'm doing wrong with the last part, I would appreciate it. Also, if any other part of my code could use some cleaning up, feel free to let me know.
Thanks!
Code:
Sub launch_send_close_outlook()
'launch Outlook
Dim Outlook As Outlook.Application
Set Outlook = CreateObject("Outlook.Application")
Dim ns As Outlook.Namespace
Dim Folder As Outlook.MAPIFolder
Set ns = Outlook.GetNamespace("MAPI")
Set Folder = ns.GetDefaultFolder(olFolderInbox)
Outlook.Explorers.Add Folder
'send email
Set myOlApp = CreateObject("Outlook.Application")
Set mailItem = myOlApp.CreateItem(olMailItem)
Set myRecipient = mailItem.Recipients.Add("name@domain.com")
mailItem.body = "testing"
mailItem.Subject = "test email"
mailItem.Send
'close Outlook
Set Outlook = CreateObject("Outlook.Application")
Outlook.Quit
Set Outlook = Nothing
End Sub
Thanks!