Outlook 2007 Delete Email Addresses

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The following macro deletes the email address from the first email area. What can I change to delete from the email2 address, and also, the email3 address?

Sub DeleteEmail1()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder

Dim objItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

On Error Resume Next

If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem

objItem.UserProperties("E-mail") = ""

objItem.Save
GoTo Leave
End If

Set objSelection = objApp.ActiveExplorer.Selection

For Each objItem In objSelection


objItem.UserProperties("E-mail") = ""



objItem.Save

Next
Leave:
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The macro is to change just to the second email field and then change just to the third email field. So what do I change each way please as I need to do it this morning! Thanks very much!
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The following macro deletes the email2 address but I only shows up as deleted if I save and close the contact and open up the contact....so is there a way that is saves the contact without having to save and close and open it?

Public Sub DeleteEmail2()
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim obj As Object

Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection

On Error Resume Next

For Each obj In Selection

Set objContact = obj

With objContact
If .Email2Address <> "" Then
.Email2Address = ""
.Save
End If
End With


Err.Clear
Next


Set obj = Nothing
Set objContact = Nothing

End Sub
 
Last edited:

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Well, this: .Save should save it - but it sounds like it's not getting refreshed. if you didn't customize the fields so they are each visible on screen, try selecting a different email address field in the email dropdown.

Are you using it on one contact or a selection of several contacts?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This works only on the currently open contact- and the address is removed, even if i don't switch address fields to refresh it. I noticed the display name field wasn't cleared and added that to it.

Code:
Public Sub DeleteEmail2()

Dim objcontact As ContactItem
On Error Resume Next


Set objcontact = Application.ActiveInspector.CurrentItem

With objcontact
If .Email2Address <> "" Then
.Email2Address = ""
.Email2DisplayName = ""
.Save
End If
End With


Err.Clear
Set objcontact = Nothing

End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I will try what you showed me above and let you know right away. And also, what can we add if I select a list of contacts from a folder....as before you showed me how to change the fields of a list of contacts that I select.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Here is what I learned, and to tell you! As to the email2 on the dropdown field of the email addresses, it deletes and I don't have to save and close and open the contact. But I added another field and the display is _RecipientControl6 and the field that you put in it is E-mail 2, and when I add to that field and save, close and open, it shows up on the dropdown field, and as to that additional field, it does not delete it until I save, close and open the contact.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Here is what I learned, and to tell you! As to the email2 on the dropdown field of the email addresses, it deletes and I don't have to save and close and open the contact. But I added another field and the display is _RecipientControl6 and the field that you put in it is E-mail 2, and when I add to that field and save, close and open, it shows up on the dropdown field, and as to that additional field, it does not delete it until I save, close and open the contact.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Here is the code that based on what you showed me before in other areas to delete, the following code deletes the email 2 address when I select the list of contacts, but again, if I run this when I open one contact, it does not delete it until I save, close and open the contact again....also, it does it on the dropdown field of email addresses without saving, closing and opening the contact.

Sub Delete_DeleteEmail2test2()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder

Dim objItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

On Error Resume Next

If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem

objItem.UserProperties("E-mail 2") = ""


objItem.Save
GoTo Leave
End If


Set objSelection = objApp.ActiveExplorer.Selection

For Each objItem In objSelection

objItem.UserProperties("E-mail 2") = ""


objItem.Save

Next

Leave:
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
so it behaves differently on custom fields? Where does the custom field get it's data from? If it reads a default field, the custom field it's set to update on some action, probably open by the sounds of it. So you need to clear the default field then save and do the action for the custom field to update.

I thought 'automatically' updated on change.

properties.png
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The place a created, I choosed the field you show above, and that works when I select a list of contacts, but not when I just open one contact.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
That's because the selected contacts are not all open - the single contacts needs to be closed and reopened. Is the field set to calculate automatically?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I don't understand what you said....I just open the contact, run the code, and when I save and close the contact, it deleted the email2 address.....I just want it to delete it without having to save and close and open again. Is there a way to do that?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The email2 address is in a custom field : objItem.UserProperties("E-mail 2") - where is it getting the data for that field? Are you entering it directly in the Email 2 custom field or is it reading Outlook's default Email2Address field?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I just have the field from Outlook that is E-mail 2 which is the value of the area I created.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The problem is that the custom field is reading the default field and it definitely won't update until the form is saved - it should update if you switch tabs (multiple pages) and might update if you move to another field. I don't know of a way to force an update.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I appreciate your help as usual!!

Also, is there a code that saves the contact but does not close it? As I have a code that saves and closes the contact.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
And here is my code that saves and closes the contract, so what can we change so it just saves the contract without closing it:

Public Sub SaveCloseContact()

Dim myinspector As outlook.inspector

Dim myItem As outlook.contactItem


Set myinspector = Application.ActiveInspector

Set myItem = myinspector.currentItem

myItem.Close olSave


End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This:
myItem.Close olSave

changed to
myItem.save

will save without closing.
 
Top