F
franjorge
Hello,
I am trying a simple VBA script in order to delete all contacts that
belong to a certain category (TData).
Here is the code
Set miExplorador = Application.ActiveExplorer
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
If miExplorador.IsFolderSelected(myFolder) = False Then
miExplorador.SelectFolder myFolder
End If
Set fld = Application.ActiveExplorer.CurrentFolder
Set contactos = fld.Items
Set contactosTData = contactos.Restrict("[Categorías] = 'TData'")
numcontactos = contactosTData.Count
Set objContact = contactosTData.GetFirst
Do While Not objContact Is Nothing
Set objCDO = GetCDOItemFromOL(objContact)
If Not objCDO Is Nothing Then
objCDO.Delete
Else
MsgBox ("Contact" & objContact.LastName & " not de deleted")
End If
Set objContact = contactosTData.GetNext
'UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + 1
Loop
I have used CDO in order to avoid the delete confirmation prompt. If I
run this code the while loop takes around 4 minutes to execute.
If instead of deleting the contacts via this script I go to the Outlook
2003 GUI, select the contacts folder, choose the 'By Category' view,
select the 'TData' category and press 'DEL' it takes half of the time
(~2 minutes) to delete the items.
My question is if my code can be optimized anyway so that it does not
take so long to delete all the contacts (there are 1650 contacts in
this category).
Another problem I have is that this code sometimes does not delete some
contacts of the category. If I run the script again, it does delete
them. I tried to catch the records that do not get deleted with the
Msgbox in the else clause, but this does not seem to be the problem.
And finally, not an specific Outlook issue (I think), but the
Progressbar line is commented out, because the UserForm1 shows up as
the code is run, but it does not get updated. In this UserForm I also
have a text label, that is not show, and the Form only shows the 'non
progressing' Progressbar. The background of the form is blank.
Too many questions, but if anyone could answer any of them I would be
very grateful.
Regards,
Fran
I am trying a simple VBA script in order to delete all contacts that
belong to a certain category (TData).
Here is the code
Set miExplorador = Application.ActiveExplorer
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
If miExplorador.IsFolderSelected(myFolder) = False Then
miExplorador.SelectFolder myFolder
End If
Set fld = Application.ActiveExplorer.CurrentFolder
Set contactos = fld.Items
Set contactosTData = contactos.Restrict("[Categorías] = 'TData'")
numcontactos = contactosTData.Count
Set objContact = contactosTData.GetFirst
Do While Not objContact Is Nothing
Set objCDO = GetCDOItemFromOL(objContact)
If Not objCDO Is Nothing Then
objCDO.Delete
Else
MsgBox ("Contact" & objContact.LastName & " not de deleted")
End If
Set objContact = contactosTData.GetNext
'UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + 1
Loop
I have used CDO in order to avoid the delete confirmation prompt. If I
run this code the while loop takes around 4 minutes to execute.
If instead of deleting the contacts via this script I go to the Outlook
2003 GUI, select the contacts folder, choose the 'By Category' view,
select the 'TData' category and press 'DEL' it takes half of the time
(~2 minutes) to delete the items.
My question is if my code can be optimized anyway so that it does not
take so long to delete all the contacts (there are 1650 contacts in
this category).
Another problem I have is that this code sometimes does not delete some
contacts of the category. If I run the script again, it does delete
them. I tried to catch the records that do not get deleted with the
Msgbox in the else clause, but this does not seem to be the problem.
And finally, not an specific Outlook issue (I think), but the
Progressbar line is commented out, because the UserForm1 shows up as
the code is run, but it does not get updated. In this UserForm I also
have a text label, that is not show, and the Form only shows the 'non
progressing' Progressbar. The background of the form is blank.
Too many questions, but if anyone could answer any of them I would be
very grateful.
Regards,
Fran