A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook wont .quit



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 2nd 09, 05:43 PM posted to microsoft.public.outlook.program_vba
Rich007
external usenet poster
 
Posts: 4
Default Outlook wont .quit

Hi,
I originally posted this under Word Programming, but I've not had any
response, so I thought I should try my luck with the friendly Outlook
Experts...

I've managed to pull together this code which tests whether Word is used as
the e-mail editor by Outlook (all Office 2003). Running the code from Word,
it appears to work well, except that if it had to open its own Outlook
application (i.e. if Outlook was NOT running at the start) it is supposed to
Quit Outlook with the
olApp.Quit line. But at the end I still have a running Outlook.exe process
in my task manager! Even more strange is that if I run the code a second
time it can't use the existing Outlook application and enters the "If Err
0 Then" loop, so it's as if Outlook was closed, but stayed in the
TaskManager...

Furthermore, if I then start Outlook from the start menu, a second
Outlook.exe appears in the TaskManager and the new Outlook hangs with a
white, empty window!

Why doesn't Outlook quit with this code?

Also, is there an easier way to do this by interogating the Outlook settings
in the registry, thus completely avoiding having to open Outlook?

Many thanks. Here's the code (all in a Word VBA module):

Sub CallTestOutlook()
Dim WordIsUsedByOutlook As String

If TestOutlook = True Then
WordIsUsedByOutlook = "IS"
Else
WordIsUsedByOutlook = "IS NOT"
End If

MsgBox "Word " & WordIsUsedByOutlook & " used by Outlook."
End Sub

Function TestOutlook() As Boolean
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olInspector As Outlook.Inspector
Dim bStarted As Boolean

'Get a handle on the Outlook Application (if it is running)
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'If Outlook is not running then start Outlook
If Err 0 Then
On Error GoTo ErrorHandler
Set olApp = CreateObject("Outlook.Application")
bStarted = True
Else
On Error GoTo ErrorHandler
End If

'Create a MailItem and and Inspector for it
Set olMail = olApp.CreateItem(olMailItem)
Set olInspector = olMail.GetInspector

'Test whether Word is used by Outlook as e-mail editor
If olInspector.IsWordMail Then
TestOutlook = True
Else
TestOutlook = False
End If

Set olInspector = Nothing
Set olMail = Nothing

'Close Outlook if it was started by this macro.
If bStarted Then
olApp.Quit
End If

Set olApp = Nothing
Exit Function
ErrorHandler:
MsgBox "Error " & Err.Number & " " & Err.Description
End Function


Cheers
Rich

Ads
  #2  
Old September 3rd 09, 12:46 AM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Outlook wont .quit

I fail to see why Outlook wouldn't quit, see if adding a line like this
would help:

olApp.Session.Logon "", "", False, False

'Create a MailItem and and Inspector for it
Set olMail = olApp.CreateItem(olMailItem)

You can check at
HKCU\Software\Microsoft\Office\11.0\Outlook\Option s\Mail\UseWordMail (a
REG_DWORD, 1 = yes). The "11.0" is specific to Outlook 2003.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Rich007" wrote in message
news
Hi,
I originally posted this under Word Programming, but I've not had any
response, so I thought I should try my luck with the friendly Outlook
Experts...

I've managed to pull together this code which tests whether Word is used
as
the e-mail editor by Outlook (all Office 2003). Running the code from
Word,
it appears to work well, except that if it had to open its own Outlook
application (i.e. if Outlook was NOT running at the start) it is supposed
to
Quit Outlook with the
olApp.Quit line. But at the end I still have a running Outlook.exe
process
in my task manager! Even more strange is that if I run the code a second
time it can't use the existing Outlook application and enters the "If Err

0 Then" loop, so it's as if Outlook was closed, but stayed in the
TaskManager...

Furthermore, if I then start Outlook from the start menu, a second
Outlook.exe appears in the TaskManager and the new Outlook hangs with a
white, empty window!

Why doesn't Outlook quit with this code?

Also, is there an easier way to do this by interogating the Outlook
settings
in the registry, thus completely avoiding having to open Outlook?

Many thanks. Here's the code (all in a Word VBA module):

Sub CallTestOutlook()
Dim WordIsUsedByOutlook As String

If TestOutlook = True Then
WordIsUsedByOutlook = "IS"
Else
WordIsUsedByOutlook = "IS NOT"
End If

MsgBox "Word " & WordIsUsedByOutlook & " used by Outlook."
End Sub

Function TestOutlook() As Boolean
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olInspector As Outlook.Inspector
Dim bStarted As Boolean

'Get a handle on the Outlook Application (if it is running)
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'If Outlook is not running then start Outlook
If Err 0 Then
On Error GoTo ErrorHandler
Set olApp = CreateObject("Outlook.Application")
bStarted = True
Else
On Error GoTo ErrorHandler
End If

'Create a MailItem and and Inspector for it
Set olMail = olApp.CreateItem(olMailItem)
Set olInspector = olMail.GetInspector

'Test whether Word is used by Outlook as e-mail editor
If olInspector.IsWordMail Then
TestOutlook = True
Else
TestOutlook = False
End If

Set olInspector = Nothing
Set olMail = Nothing

'Close Outlook if it was started by this macro.
If bStarted Then
olApp.Quit
End If

Set olApp = Nothing
Exit Function
ErrorHandler:
MsgBox "Error " & Err.Number & " " & Err.Description
End Function


Cheers
Rich


  #3  
Old September 3rd 09, 01:26 AM posted to microsoft.public.outlook.program_vba
Rich007
external usenet poster
 
Posts: 4
Default Outlook wont .quit

Hi Ken, thank you so much for responding.
I tried your suggested extra line of code before creating the MailItem, but
it made no difference. So I tried gradually commenting out lines of code
until Outlook does quit. It appears to be the line:
Set olInspector = olMail.GetInspector
that is causing the issue. If I don't call that line Outlook quits as
ordered. If I do include that line, Outlook stays in the TaskManager. Any
ideas?

Thanks also for providing the registry address. I have never used VBA to
interogate the registry. Would you recommend I use the API route as
described he http://support.microsoft.com/default.aspx/kb/145679 ...or
go down the scripting route as described he
http://vba-corner.livejournal.com/3054.html ?
(these are the first two results I've found in Google).

Thanks again.
Cheers
Rich



"Ken Slovak - [MVP - Outlook]" wrote:

I fail to see why Outlook wouldn't quit, see if adding a line like this
would help:

olApp.Session.Logon "", "", False, False

'Create a MailItem and and Inspector for it
Set olMail = olApp.CreateItem(olMailItem)

You can check at
HKCU\Software\Microsoft\Office\11.0\Outlook\Option s\Mail\UseWordMail (a
REG_DWORD, 1 = yes). The "11.0" is specific to Outlook 2003.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Rich007" wrote in message
news
Hi,
I originally posted this under Word Programming, but I've not had any
response, so I thought I should try my luck with the friendly Outlook
Experts...

I've managed to pull together this code which tests whether Word is used
as
the e-mail editor by Outlook (all Office 2003). Running the code from
Word,
it appears to work well, except that if it had to open its own Outlook
application (i.e. if Outlook was NOT running at the start) it is supposed
to
Quit Outlook with the
olApp.Quit line. But at the end I still have a running Outlook.exe
process
in my task manager! Even more strange is that if I run the code a second
time it can't use the existing Outlook application and enters the "If Err

0 Then" loop, so it's as if Outlook was closed, but stayed in the
TaskManager...

Furthermore, if I then start Outlook from the start menu, a second
Outlook.exe appears in the TaskManager and the new Outlook hangs with a
white, empty window!

Why doesn't Outlook quit with this code?

Also, is there an easier way to do this by interogating the Outlook
settings
in the registry, thus completely avoiding having to open Outlook?

Many thanks. Here's the code (all in a Word VBA module):

Sub CallTestOutlook()
Dim WordIsUsedByOutlook As String

If TestOutlook = True Then
WordIsUsedByOutlook = "IS"
Else
WordIsUsedByOutlook = "IS NOT"
End If

MsgBox "Word " & WordIsUsedByOutlook & " used by Outlook."
End Sub

Function TestOutlook() As Boolean
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olInspector As Outlook.Inspector
Dim bStarted As Boolean

'Get a handle on the Outlook Application (if it is running)
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'If Outlook is not running then start Outlook
If Err 0 Then
On Error GoTo ErrorHandler
Set olApp = CreateObject("Outlook.Application")
bStarted = True
Else
On Error GoTo ErrorHandler
End If

'Create a MailItem and and Inspector for it
Set olMail = olApp.CreateItem(olMailItem)
Set olInspector = olMail.GetInspector

'Test whether Word is used by Outlook as e-mail editor
If olInspector.IsWordMail Then
TestOutlook = True
Else
TestOutlook = False
End If

Set olInspector = Nothing
Set olMail = Nothing

'Close Outlook if it was started by this macro.
If bStarted Then
olApp.Quit
End If

Set olApp = Nothing
Exit Function
ErrorHandler:
MsgBox "Error " & Err.Number & " " & Err.Description
End Function


Cheers
Rich



  #4  
Old September 3rd 09, 03:13 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Outlook wont .quit

In that case try closing the Inspector object when you're done with it,
before you set it to Nothing.

Six of one, half dozen of another as far as reading the registry for that
value. What are you most comfortable with? The only caution is if someone is
running A-V with one of those script stoppers it might prevent the script
access from working.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Rich007" wrote in message
...
Hi Ken, thank you so much for responding.
I tried your suggested extra line of code before creating the MailItem,
but
it made no difference. So I tried gradually commenting out lines of code
until Outlook does quit. It appears to be the line:
Set olInspector = olMail.GetInspector
that is causing the issue. If I don't call that line Outlook quits as
ordered. If I do include that line, Outlook stays in the TaskManager.
Any
ideas?

Thanks also for providing the registry address. I have never used VBA to
interogate the registry. Would you recommend I use the API route as
described he http://support.microsoft.com/default.aspx/kb/145679
...or
go down the scripting route as described he
http://vba-corner.livejournal.com/3054.html ?
(these are the first two results I've found in Google).

Thanks again.
Cheers
Rich


  #5  
Old September 3rd 09, 07:56 PM posted to microsoft.public.outlook.program_vba
Rich007
external usenet poster
 
Posts: 4
Default Outlook wont .quit

That's it! Thank you Ken.
I needed to close BOTH the Inspector AND the MailItem before calling the
..quit command. All works fine now, although I suspect I will interogate the
registry rather than Outlook itself, since Outlook is slow when it starts
(and if it is open for long enough the calendar reminders can pop up!). I
got the registry query functions working using the API functions provided at
this site:
http://support.microsoft.com/default.aspx/kb/145679

Incidentally, the 2 registry values that sets whether Word is used by
Outlook 2003 are at:
[HKCU\] Software\Microsoft\Office\11.0\Outlook\Options\Mai l
"UseWordMail" is 1 if the "Use Microsoft Office Word 2003 to read Rich Text
e-mail messages" is checked (zero if not).
and
"EditorPreference" which corresponds to the "Use Microsoft Office Word 2003
to edit e-mail messages" checkbox has the following values:
Word is NOT used if EditorPreference is set to either:
' 131072 = HTML/Outlook
' 196610 = Rich Text/Outlook
' 65536 = Plain Text/Outlook

Word IS used if EditorPreference is set to either:
' 196609 = Rich Text/Microsoft Word
' 65537 = Plain Text/Microsoft Word
' 131073 = HTML/Microsoft Word

So my macro for interogating the registry has to test for all these values.

In case anyone else does want to work directly with Outlook to determine
these settings, here is the working function to do it (returns true or false).

Function TestOutlook() As Boolean
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olInspector As Outlook.Inspector
Dim bStarted As Boolean

'Get a handle on the Outlook Application (if it is running)
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'If Outlook is not running then start Outlook
If Err 0 Then
On Error GoTo ErrorHandler
Set olApp = CreateObject("Outlook.Application")
bStarted = True
Else
On Error GoTo ErrorHandler
End If

'Create a MailItem and an Inspector for it
Set olMail = olApp.CreateItem(olMailItem)
Set olInspector = olMail.GetInspector

'Test whether Word is used by Outlook as e-mail editor
If olInspector.IsWordMail Then
TestOutlook = True 'Function output
Else
TestOutlook = False 'Function output
End If

'Close the Inspector and the MailItem
olInspector.Close (olDiscard) 'MUST HAVE THESE FOR OUTLOOK TO QUIT!
olMail.Close (olDiscard)

'Close Outlook if it was started by this macro.
If bStarted Then
olApp.Quit
End If

'Clean up
Set olInspector = Nothing
Set olMail = Nothing
Set olApp = Nothing
Exit Function
ErrorHandler:
MsgBox "Error " & Err.Number & " " & Err.Description
End Function


Thanks again Ken.
Cheers
Rich

"Ken Slovak - [MVP - Outlook]" wrote:

In that case try closing the Inspector object when you're done with it,
before you set it to Nothing.

Six of one, half dozen of another as far as reading the registry for that
value. What are you most comfortable with? The only caution is if someone is
running A-V with one of those script stoppers it might prevent the script
access from working.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Rich007" wrote in message
...
Hi Ken, thank you so much for responding.
I tried your suggested extra line of code before creating the MailItem,
but
it made no difference. So I tried gradually commenting out lines of code
until Outlook does quit. It appears to be the line:
Set olInspector = olMail.GetInspector
that is causing the issue. If I don't call that line Outlook quits as
ordered. If I do include that line, Outlook stays in the TaskManager.
Any
ideas?

Thanks also for providing the registry address. I have never used VBA to
interogate the registry. Would you recommend I use the API route as
described he http://support.microsoft.com/default.aspx/kb/145679
...or
go down the scripting route as described he
http://vba-corner.livejournal.com/3054.html ?
(these are the first two results I've found in Google).

Thanks again.
Cheers
Rich



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
In Outlook, a read receipt message wont send and wont delete MikeT Outlook - General Queries 4 July 9th 08 02:13 AM
Once Outlook was quit, it cannot be restarted Oriolus Outlook - Installation 10 July 25th 07 11:06 AM
Outlook just quit working Sharon Outlook - Installation 2 June 4th 07 02:57 AM
windows installer wont quit irish Outlook - General Queries 2 August 25th 06 11:44 PM
Outlook does not quit properly S Church Outlook - Installation 1 April 16th 06 07:36 PM


All times are GMT +1. The time now is 09:11 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.