Jump to content

OutlookEX.au3 find and delete contacts with special selection


Go to solution Solved by water,

Recommended Posts

Posted

Hello Forum,

I want to use the OutlookEX.au3 to add und to remove contacts to my Outlook. An contact add works fine for me. But from time to time I have some duplicate contacts, regarding the help file and forum a synchronization is currently not available. So far my idea:

1. Very first run: I add contacts with a "special tag" in the outlook field "body". for example "IwasaddedbyAutoIT".
2. Next run: I search and delete all contacts with the "special tag"
3. normal import / reimport. So I can get sure I will not have duplicate contacts.

and currently Iam not able to search with the OutlookEX.au3 - I have found examples with calenders but nothing with contacts und with a "select". Could maybe anyone spend a tip? Thx a lot!

Posted

I would use something like this:

  • First you need to define what you call a "duplicate contact". Name, Firstname, Company ...
  • Read all contacts with the defined properties + EntryID into an array (makes searching much faster)
  • For each contact to import loop throught the array and compare properties
  • When a duplicate contact is found you need to decide how to process this items: delete the existing or the new contact, merge properties from the new contact to the existing one ...?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hello Water, thx for re

my import list contains: FirstName,Lastname,BusinessTelephoneNumber,Email1Address,CompanyName,MobileTelephoneNumber,JobTitle,body,Title

When I import my import list I have "3000 contacts" in outlook. Works fine.

When something is changing in my import list I would have 6000 contacts in my outlook. My idia was at the filed body to at "autoimport generated" or something like that.
Idia: 1. search in outlook for all contacts with body "autoimport generated". 2. delete the "search result" in outlook 3. import a "freh "updated" import list".

If available / possible I would also use a sync method.

My current need ist to search with my "body" filter and delete the results in outlook. This would be great.
 

 

 

 

 

Posted

You could create a category named "AutoImport generated" and assign this category to all imported contacts.
When a new import is needed search for this category and delete all returned contacts.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hello Water,

thx for re. For both ways: Could you help me with a code snippet?
I just revieve syntax Error with the "appointment" sample wich I have found from u.

Posted

Before we start coding I would like to be sure we select the best approach.

Are you sure that none of the contacts to be imported overlap with existing contacts? So we do not create duplicates?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

IAm sure, cause I will filter / select with my "body filed" - so iam fine. Existing "local" account get not touched. So I update only "my" import list.

Posted

PAP:

1. Del all contacts with "select where xzy autoimport at filed body"

2. Import "new" list

Existing accounts / overlapping does not exist / will have no effect.

Posted

Do you already have contacts with the "autoimport" flag in the body?
I suggest to use a regular property of the contact item as this is much faster - not unimportant when importing thousands of contacts.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hello Water,

thats right. I "get" them with the flag at the body fild.

currently I have first success with the array with all contacts with:

$aResult = _OL_ItemFind($oOL, "*\Kontakte", $olContact, "", "", "", "FirstName,Lastname,BusinessTelephoneNumber,Email1Address,CompanyName,MobileTelephoneNumber,JobTitle,body,Title", "")

next I try to implement the filter "body" - so I recieve just the wanted contacts. next I need just to delete them. Than its ready.

Posted

I hope you added the "Flag" at the top of the body.
Else you will run into problems when the body has > 255 characters as described here.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
$aResultOutlookBestand = _OL_ItemFind($oOL, "*\Kontakte", $olContact, "[nickname]='RecuraAutoImport'", "", "", "EntryID,FirstName,Lastname,BusinessTelephoneNumber,Email1Address,CompanyName,MobileTelephoneNumber,JobTitle,nickname,Title", "")

This I use to search for existing contacts. I get an Array with all data.

 

At that moment I understand what u mean with "time" at deleting 🙂

If I use:

While $k <= $iRowsOutlookBestand
_OL_ItemDelete($oOL, $aResultOutlookBestand[1][0])

$aResultOutlookBestand = _OL_ItemFind($oOL, "*\Kontakte", $olContact, "[nickname]='RecuraAutoImport'", "", "", "EntryID,FirstName,Lastname,BusinessTelephoneNumber,Email1Address,CompanyName,MobileTelephoneNumber,JobTitle,nickname,Title", "")
$iRowsOutlookBestand = UBound($aResultOutlookBestand, $UBOUND_ROWS) ; Zähle die Array Einträge für die Manipulation "Recura Export for Outlook".
$iRowsOutlookBestand = ($iRowsOutlookBestand - "1"); Wichtig ist -1 weil das Array ja "zu groß" für die Lösch-Routine ist! Display Array vergleichen mit ResultCount!

WEnd

I "rescan" the contacts to get the current Entry ID. That progress is time intensive. Is it possible to delete all "findings"  / the whole array with all entry IDs at once? Outlook seems here problematic.

 

 

Posted

Yes, this is possible with ther _OL_ItemBulk function.
This is UNTESTED:

$aResultOutlookBestand = _OL_ItemFind($oOL, "*\Kontakte", $olContact, "[nickname]='RecuraAutoImport'", "", "", "@ItemObject")
$aErrors = _OL_ItemBulk($oOL, $aResultOutlookBestand, Default, Default, 2, Default, Default, 1)
If @error <> 0 Then
    MsgBox(16, "_OL_ItemBulk", "Error deleting specified items. @error = " & @error & ", @extended = " & @extended)
    If $iFlag = 1 Then _ArrayDisplay($aErrors)
EndIf

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Tested. works fine:

if $iRowsOutlookBestand >0 Then

While $k <= $iRowsOutlookBestand

_OL_ItemDelete($oOL, $aResultOutlookBestand[1][0])

If @error Then ExitLoop

global $aErrors
Global $iFlag

$aResultOutlookBestand = _OL_ItemFind($oOL, "*\Kontakte", $olContact, "[nickname]='RecuraAutoImport'", "", "", "@ItemObject")
$aErrors = _OL_ItemBulk($oOL, $aResultOutlookBestand, Default, Default, 2, Default, Default, 1)

$aResultOutlookBestand = ($aResultOutlookBestand - 2)

If @error <> 0 Then
    MsgBox(16, "_OL_ItemBulk", "Fehler beim Outlookkontakte synchronisieren. @error = " & @error & ", @extended = " & @extended)
    If $iFlag = 1 Then _ArrayDisplay($aErrors)
EndIf

 

Sorry but my last question.

If I use

Global $bPermanent
Global $sStoreID
_OL_ItemDelete($oOL, $aResultOutlookBestand[1][0],$sStoreID = Default,$bPermanent = TRUE)

Outlook deletes the contact elements from my contacts --> great. But it keeps them at the deletet object. I have found threats were u say thats not possible but with a trick is possible. Could you tell me that trick? Than its fine.

Posted

Have a look at function _OL_ItemDelete. The item is first moved to the $olFolderDeletedItems folder and then deleted.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Ive read the help for the function and other threads.

does I unterstand permanend wrong? permanend means for me "direct delete without getting into "deleted elements"". iam wrong?

Currently I tried everything but my contacts still land in "deleted elements":

_OL_ItemDelete($oOL, $aResultOutlookBestand[1][0],"",TRUE)

 

Interresting:

When I use the search function I cant with elements in deleted objects with a filter --> without filter I can found elements. Is there a special handling for that folder?
My idea was to research the deleted elements --> and delete them again. But my result is always empty because the "selection" works not for me.

Posted

The Delete method always moves the item to the Deleted Items folder. To permanently delete the item you have to delete it from the Deleted items folder.
Unfortunately the EntryID changes when the item is moved to the Deleted items folder and the Delete method does not return this new EntryID.

Please see:
https://learn.microsoft.com/en-us/office/vba/outlook/how-to/items-folders-and-stores/working-with-entryids-and-storeids and
https://learn.microsoft.com/en-in/office/vba/api/outlook.contactitem.delete

That's why I first move the item and then delete it.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

OK, thats I have seen 🙂

Than my problem keeps when i filter with / try to get results from the deleted folder:
 

$aResultOutlookBestand = _OL_ItemFind($oOL, "*\Deleted item", $olContact, "[nickname]='RecuraAutoImport'", "", "", "EntryID,FirstName,Lastname,BusinessTelephoneNumber,Email1Address,CompanyName,MobileTelephoneNumber,JobTitle,nickname,Title", "")

If I use [nickname]='RecuraAutoImport' = result = 0
If I use no selection / filter, "", I can find my Items. Does I have to search with other options at deleted folder? Does I have understand something wrong hat helpfile? Thx!

Posted

In one of the above posts you use the german name of a folder "*\Kontakte" now you use the english name ("*\Deleted item").
Can you please check the correct folder names?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...