The code I use requires CDO, which may not be available since it's an
optional installation for Outlook 2000 and later. First I get the Outlook
version (Application.Version) as a string and look at the 2 left characters
of the string. If the leftmost one is "9" it's Outlook 2000, if "10" it's
Outlook 2002 and if "11" it's Outlook 2003. Then I call the following
procedure.
' olConnectMode is a global defined as follows:
Public Enum OL2003ConnectionMode
CacheConnectDrizzle = 600
CacheConnectFull = 700
CacheConnectHeaders = 500
CacheDisconnect = 400
CacheOffline = 200
Disconnect = 300
NoExchange = 0
Offline = 100
Online = 800
End Enum
Public olConnectMode As OL2003ConnectionMode
Private Function UserOnline() As Boolean
On Error Resume Next
Const PR_STORE_OFFLINE = &H6632000B
Const CdoPR_PROVIDER_DISPLAY = &H3006001E
UserOnline = False
olConnectMode = Online
With g_objDefaultInfoStore 'gotten by using Inbox.StoreID and
Session.GetInfoStore
If g_lngVersion >= 10 Then 'g_lngVersion set as Outlook version as a
Long
UserOnline = Not (g_objApp.Session.Offline) 'not available for Outlook
2000
If g_lngVersion = 10 Then
If Not UserOnline Then
olConnectMode = Offline
End If
ElseIf g_lngVersion = 11 Then
olConnectMode = g_objApp.Session.ExchangeConnectionMode
If InStr(1, .Fields(CdoPR_PROVIDER_DISPLAY), _
"Microsoft Exchange", vbTextCompare) > 0 Then
If ((UserOnline) And (olConnectMode = NoExchange)) Then
olConnectMode = Offline
End If
End If
End If
Else
If InStr(1, .Fields(CdoPR_PROVIDER_DISPLAY), "Microsoft Exchange", _
vbTextCompare) > 0 Then
'Check if store is in offline mode
UserOnline = Not (.Fields(PR_STORE_OFFLINE).Value)
ElseIf InStr(1, .Fields(CdoPR_PROVIDER_DISPLAY), "Personal Folders", _
vbTextCompare) > 0 Then
UserOnline = True
End If
If Not UserOnline Then
olConnectMode = Offline
End If
End If
End With
If Err <> 0 Then
LogAddInErr Err, "clsAddin", "UserOnline", "Error!"
'Err.Clear
End If
End Function