To remove an Account object programmatically, first select the object and then call the Delete method. The following C# and Visual Basic for Applications (VBA) examples show how to delete a new Account object.
string strQuery = "[FileAs] = 'Wide World Importers'";
Outlook.ContactItem accountItem = (Outlook.ContactItem)accountsFolder.Items.Find(strQuery);
if (accountItem != null)
{
accountItem.Delete();
}
else
{
Console.WriteLine("Account not found");
}
}
Sub DeleteAccount()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim bcmRootFolder As Outlook.Folder
Dim olFolders As Outlook.Folders
Dim bcmAccountsFldr As Outlook.Folder
Dim existAcct As Outlook.ContactItem
Set olApp = CreateObject("Outlook.Application")
Set objNS = olApp.GetNamespace("MAPI")
Set olFolders = objNS.Session.Folders
Set bcmRootFolder = olFolders("Business Contact Manager")
Set bcmAccountsFldr = bcmRootFolder.Folders("Accounts")
Set existAcct = bcmAccountsFldr.Items.Find("[FileAs] = 'Wide World'")
If Not TypeName(existAcct) = "Nothing" Then
existAcct.Delete
Else
MsgBox ("No account found with Full Name Wide World Importers")
End If
Set existAcct = Nothing
Set bcmAccountsFldr = Nothing
Set olFolders = Nothing
Set bcmRootFolder = Nothing
Set objNS = Nothing
Set olApp = Nothing