Checks whether the specified email account exists in Microsoft Outlook. Requires Microsoft Office 2007 or newer. Returns true if the email account exists and false if it doesn’t.
Table of Contents
Function
VBAFunction EmailAccountExists(strAccount As String) As Boolean Dim olApp As Object, olNS As Object Dim varItem As Variant Set olApp = CreateObject("Outlook.Application") Set olNS = olApp.GetNamespace("MAPI") For Each varItem In olApp.Session.Accounts If varItem.SmtpAddress = strAccount Then EmailAccountExists = True Exit Function End If Next varItem End Function
Parameters
Name | Optional/ Required | Data type | Description |
strAccount | Required | String | The name of the email account to be checked. |
Usage example
VBASub TestEmailAccountExists() Debug.Print EmailAccountExists("test@test.com") ' true = email account exists, false = email acccount does not exist End Sub