home | get Sue’s code | forums | share code | registration

More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

Login

login
password
Remember me

You will need to register and log in if you want to download the source code for the Microsoft Outlook Programming book. The forums and code sharing areas are open to both registered and non-registered visitors.

share code 09-Feb-2010 09:24

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

 

Code level: beginner    Code area: Basic Outlook Printer Friendly Version
Title: How to determine whether or not Outlook is visible
Description: Unlike other Office products, Outlook does not expose a visible property. However, if it is visible then either an explorer or an inspector is being used. This code checks their counts and returns a boolean value based on them.
Date: 23-Oct-2003  08:38
Code level: beginner
Code area: Basic Outlook
Posted by: Gary Winey
Body:
All 1comments
Page [ 1  
  24-Oct-2003  11:40   
Here is a better version. By changing the parm type to Variant it will properly handle non objects by returning False. Also, assigning the counts to a variable allows opportunity for trapping errors (eg a non Outlook Application object was passed) which will also return False. Finally, at the bottom is a sub with several types of variables passed into the function for testing purposes.

'****************************************************************
'* Name: IsOutlookVisible
'* Type: Function
'* Args: Outlook application object
'* Returns: True if Outlook is visible, otherwise False
'* Comments: If outlook is visible then either an explorer or
'* an inspector must be in use. If both are 0 then
'* Outlook is not visible.
'* Sample:
'* Sub TestIt
'* Dim obj As Object
'* On Error Resume Next 'Handle errors here
'* Set obj = GetObject(, "Outlook.Application")
'* If Err.Number Then
'* Err.Clear
'* Set obj = CreateObject("Outlook.Application")
'* End If
'* If IsOutlookVisible(obj) Then
'* MsgBox "Outlook is visible"
'* End If
'* Set obj = Nothing 'Release object
'* On Error GoTo 0 'Reset error handling
'* End Sub
'****************************************************************
Public Function IsOutlookVisible(OutlookApp As Variant) As Boolean
Dim lngX As Long
    On Error Resume Next 'Handle errors here
    If IsObject(OutlookApp) Then 'Ensure we have an object
        With OutlookApp
            'Will cause error if not Outlook Application object
            lngX = .Explorers.Count + .Inspectors.Count
            If Err.Number Then
                Err.Clear 'Not Outlook Application
            Else
                IsOutlookVisible = (lngX > 0)
            End If
        End With
    End If
    On Error GoTo 0 'Reset error handling
End Function 'IsOutlookVisible

Sub TestIt()
Dim var As Variant
    Set var = ThisOutlookSession
    MsgBox IsOutlookVisible(var)
    Set var = ThisOutlookSession.ActiveExplorer
    MsgBox IsOutlookVisible(var)
    Set var = Nothing
    MsgBox IsOutlookVisible(var)
    var = 10
    MsgBox IsOutlookVisible(var)
    var = False
    MsgBox IsOutlookVisible(var)
End Sub

 
Page [ 1  
Post your comment



name        email