Outlook staying in memory

Status
Not open for further replies.
R

Rod

I am running a VBA program in Access to send emails. The email is sent OK

but Outlook stays in memory.

In the code below I have put in a message box to slow the code down. If this

is there then Outlook correctly closes itself down.

Because it is not closed it creates problems the next time I call the code,

even if it is modified to pick up an already open version of outlook.

I am using Office 2002 on a Vista machine with several cpus

Any suggestions please

many thanks

Public Sub Create_eMails()

Dim olApp As New Outlook.Application

Dim olNs As Outlook.NameSpace

Dim OBmailItem As Outlook.MailItem

Set olApp = New Outlook.Application

Set olNs = olApp.GetNamespace("MAPI")

olNs.Logon ""

Set OBmailItem = olApp.CreateItem(olMailItem)

OBmailItem.To = "Me@Home.com"

OBmailItem.Subject = "Test Email. "

OBmailItem.Body = "Test Body Text "

OBmailItem.Send

Call MsgBox("Wait")

olNs.Logoff

olApp.Quit

Set OBmailItem = Nothing

Set olNs = Nothing

Set olApp = Nothing

End Sub
 
K

Ken Slovak - [MVP - Outlook]

You need to allow time for the send operation to finish. You can try using a

DoEvents() call, but I don't think that will do it. Best thing to do

probably is to start a Send/Receive operation and wait for that to finish.

If you get a handle to SyncObjects(1) and call that SyncObject's Start()

method with an event handler for SyncEnd that should do it:

Dim WithEvents synch As Outlook.SyncObject ' in a class that can handle

events

Dim blnFinished As Boolean

When you call send you then use this:

blnFinished = False

Set synch = olNS.SyncObjects.Item(1)

synch.Start

While blnFinished = False

DoEvents

Loop

Your handler would look like this:

Private Sub synch_SyncEnd()

blnFinished = True

End Sub

"Rod" <rodrodrodrod@hotmail.com> wrote in message

news:%23OIhR8y6JHA.1716@TK2MSFTNGP03.phx.gbl...
> I am running a VBA program in Access to send emails. The email is sent OK
> but Outlook stays in memory.
> In the code below I have put in a message box to slow the code down. If
> this is there then Outlook correctly closes itself down.
> Because it is not closed it creates problems the next time I call the
> code, even if it is modified to pick up an already open version of
> outlook.

> I am using Office 2002 on a Vista machine with several cpus

> Any suggestions please

> many thanks

> > Public Sub Create_eMails()

> Dim olApp As New Outlook.Application
> Dim olNs As Outlook.NameSpace
> Dim OBmailItem As Outlook.MailItem

> Set olApp = New Outlook.Application

> Set olNs = olApp.GetNamespace("MAPI")
> olNs.Logon ""

> Set OBmailItem = olApp.CreateItem(olMailItem)

> OBmailItem.To = "Me@Home.com"

> OBmailItem.Subject = "Test Email. "
> OBmailItem.Body = "Test Body Text "
> OBmailItem.Send

> Call MsgBox("Wait")

> olNs.Logoff

> olApp.Quit

> Set OBmailItem = Nothing
> Set olNs = Nothing
> Set olApp = Nothing

> End Sub
>
 
R

Rod

Thanks, I give it a go, I've never played with evens before.
<kenslovak@mvps.org> wrote in message

news:eYf0m416JHA.1416@TK2MSFTNGP04.phx.gbl...
> You need to allow time for the send operation to finish. You can try using
> a DoEvents() call, but I don't think that will do it. Best thing to do
> probably is to start a Send/Receive operation and wait for that to finish.
> If you get a handle to SyncObjects(1) and call that SyncObject's Start()
> method with an event handler for SyncEnd that should do it:

> Dim WithEvents synch As Outlook.SyncObject ' in a class that can handle
> events
> Dim blnFinished As Boolean

> When you call send you then use this:

> blnFinished = False
> Set synch = olNS.SyncObjects.Item(1)
> synch.Start

> While blnFinished = False
> DoEvents
> Loop

> Your handler would look like this:

> Private Sub synch_SyncEnd()
> blnFinished = True
> End Sub

> >

>

> "Rod" <rodrodrodrod@hotmail.com> wrote in message
> news:%23OIhR8y6JHA.1716@TK2MSFTNGP03.phx.gbl...
> >I am running a VBA program in Access to send emails. The email is sent OK
> >but Outlook stays in memory.
> > In the code below I have put in a message box to slow the code down. If
> > this is there then Outlook correctly closes itself down.
> > Because it is not closed it creates problems the next time I call the
> > code, even if it is modified to pick up an already open version of
> > outlook.
>

>> I am using Office 2002 on a Vista machine with several cpus
>

>> Any suggestions please
>

>> many thanks
>

>
>> ------------------------------>

>
>> Public Sub Create_eMails()
>

>> Dim olApp As New Outlook.Application
> > Dim olNs As Outlook.NameSpace
> > Dim OBmailItem As Outlook.MailItem
>

>> Set olApp = New Outlook.Application
>

>> Set olNs = olApp.GetNamespace("MAPI")
> > olNs.Logon ""
>

>> Set OBmailItem = olApp.CreateItem(olMailItem)
>

>> OBmailItem.To = "Me@Home.com"
>

>> OBmailItem.Subject = "Test Email. "
> > OBmailItem.Body = "Test Body Text "
> > OBmailItem.Send
>

>> Call MsgBox("Wait")
>

>> olNs.Logoff
>

>> olApp.Quit
>

>> Set OBmailItem = Nothing
> > Set olNs = Nothing
> > Set olApp = Nothing
>

>> End Sub
> >


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C What folders are needed when reinstalling Outlook 2010 Using Outlook 0
M Respond to Outlook Email Outlook VBA and Custom Forms 0
P Color Code or highlight folders in Outlook 2016 Using Outlook 2
U Outlook locking up when replying to Email Using Outlook 4
J Outlook Autocomplete (Recipients) opens upward Using Outlook 2
A "Get Add-Ins" - Which Version of Outlook to use Using Outlook 1
O Newbie question: how to sync two Outlook -Exchange and IMAP- calendars? Using Outlook 4
P Syncing Outlook & iPhone Calendars Using Outlook 3
S Unable to extract text from an Outlook email message Using Outlook 2
O Outlook on Android: after sharing / sending a news article, draft remains open. Why? Using Outlook 1
T Outlook creates a copie of every mail I send Using Outlook.com accounts in Outlook 4
O Outlook - hidden contacts? Using Outlook 2
F Outlook 365 is "Possessed" Using Outlook 2
e_a_g_l_e_p_i Can someone explain syncing with Outlook and Gmail Using Outlook 3
K Outlook Office 365 VBA download attachment Outlook VBA and Custom Forms 2
e_a_g_l_e_p_i Gmail in Outlook 2010 preview issue Using Outlook 4
I Outlook is stuck at "Updating Calendar" Using Outlook 1
AmonRa Outlook 365 calendar - too much white space Using Outlook 0
e_a_g_l_e_p_i Outlook 2010 Help setting up Gmail account in Outlook 2010 Using Outlook 3
C-S-R How to clear an Outlook (To Do) Task Flag? Using Outlook 8
N How do I make Outlook autocomplete addresses from a list of recognised <full_names> only? Using Outlook 2
P Outlook 2019 UI changes after 20H2 update Using Outlook 1
R How to restrict GWSMO sync to Outlook Send/Receive cycles Using Outlook 0
B Outlook 2016 Unable to view images or logos on the outlook 2016 emails the same html code works well when i use outlook 2010 Using Outlook 0
S Outlook 2007 crash linked to gdiplus.dll Using Outlook 0
P Sending email from outlook IMAP to GMAIL where embedded images are added as attachment Using Outlook 1
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0
T The Linked Image Cannot Be Displayed in Outlook Using Outlook 5
M Outlook 2010 Outlook 2010 with O365 / Exchange Online Using Outlook 0
S Outlook 2016 Change how Outlook shows me contacts in emails Using Outlook 0
A OutLook For Mac 16.46 Comes Up In Small Window When Opening Using Outlook 4
S Outlook 2007 - Automatic purge fail Using Outlook 0
T Outlook creating unwanted tasks in Tasks and Todo from emails Using Outlook 1
V vBA for searching a cell's contents in Outlook and retrieving the subject line Outlook VBA and Custom Forms 1
B vBA for exporting excel file from outlook 2016 Outlook VBA and Custom Forms 3
Horsepower Moving emails between folder Outlook for Mac Outlook Wishlist 8
Travis Lloyd Messages Won't Display In Outlook 2019 Home & Business Using Outlook 0
J Outlook 2019 i dont want to buy the snake oil ost to pst programs Using Outlook 1
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
T Outlook Template - textbox visible based on combobox selection Using Outlook 1
D We're sorry but outlook has run into an error Using Outlook 6
F Outlook 2010 Outlook 2010 and GMail Using Outlook 0
M Reverting The Outlook Search Box Location (or other undesired additions) Using Outlook 1
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
P i-Phone 6s Plus receiving 2 notifications from Outlook email Using Outlook 1
C WARNING - DO NOT USE AN OUTLOOK.COM ADDRESS FOR GOOGLE ACCOUNT RECOVERY EMAIL Using Outlook 10
D Outlook 2016 Unable to load Outlook data pst file Using Outlook 5
M White square in body of Outlook Messages (O2016 Version 2012 32bit Click To Run) Using Outlook 4
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
R Why doesn't outlook use "Normal" style for new messages? Using Outlook 4

Similar threads

Top