Reputation: 1885
I want to check if the exchange server configured with the Outlook account is available before proceeding with my script. Currently, I don't check and if there's a connectivity issue the script will hang forever on this line
Set m_objNS = m_objOutlook.GetNamespace("MAPI")
and appear unresponsive.
If there's no way to do that from within the Outlook API, is there a way I could retrieve the exchange server address and ping it or set a 20 second timeout on the .GetNameSpace function?
Update: If there's a problem with the network adapter (like if it's disabled), the code can access the namespace object. The exchange mode will always be 400 until there's a prompt to authorise the code and the user accepts it. However, if there's a real (non-test purpose issue) like the exchange server is down (destination host unreachable), Outlook idle in the state "trying to connect" and you can't access .Session object or the MAPI.
There must be a way to tell if the server is down.
Upvotes: 2
Views: 4581
Reputation: 41
Excel can return the status with a series of values. You can do an If then else to respond to the status in different ways. Notably if it is "trying to connect" it reports that it's Disconnected (300) at least in Outlook 2010.
Here is the code to return the value (msgbox in there just for ease of testing). The reference values in comments of the code but also available here: http://msdn.microsoft.com/en-us/library/office/ff868474(v=office.14).aspx
Sub CheckExchangeStatus()
'olCachedConnectedDrizzle olCachedConnectedFull olCachedConnectedHeaders olCachedDisconnected olCachedOffline olDisconnected olNoExchange olOffline olOnline
'600 700 500 400 200 300 0 100 800
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Set olNameSpace = olApp.GetNamespace("MAPI")
Dim ExchangeStatus As OlExchangeConnectionMode
ExchangeStatus = olNameSpace.ExchangeConnectionMode
MsgBox (ExchangeStatus)
End Sub
Upvotes: 3
Reputation: 8033
not sure what your scriptd does so without knowing here is my suggestion.
use the session object to determine if the account is offline.
assuming m_objOutlook is an Outlook.Application object
m_objOutlook.Session.Offline
or use the ExchangeConnectionMode
objOutlook.Session.ExchangeConnectionMode
and check for one of the below
olOffline
olNoExchange
olDisconnected
olCachedOffline
olCachedDisconnected
Upvotes: 1