WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE and Outlook
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Delete Outlook Contact


Question:

Using the CreateDistributionList function off of the Tech DataBase area, and tying it to our A/D, I'm able to build DistLists of our user community. The problem is that the function creates a contact to add it to the DistList and I don't know how to delete the user once it's added.

Answer:

If your Outlook client has TOOLS/RECORD A MACRO menus, then record a macro of deleting a contact, then EDIT the macro and translate it to WinBatch.

Note: Some version of Outlook will let you run macros, but not record them.

Here is some UNDEBUGGED code that should help get you started...


searchname = "Deana Dahley"
;--------------------------------------------------------------------------------------------------------------------------
; Connect to Outlook contacts folders and search
;-------------------------------------------------------------------------------------------------------------------------- 

olFolderContacts = 10 
objOutlook = ObjectOpen("Outlook.application")
objNameSpace = objOutlook.GetNameSpace("MAPI")
objFolder = objNameSpace.GetDefaultFolder(olFolderContacts)
objContactItems = objFolder.Items
Count = objContactItems.count
flag = 0 
data = ""
; Scan through all contacts
For xx = 1 to count
	objContact = objContactItems.item(xx)
	ErrorMode(@off)
	name=objContact.FullName
	ErrorMode(@cancel)
	if name == 0 ||Strtrim(name)=="" then Continue
	if Strlower(name)==Strlower(searchname)
		if AskYesNo(StrCat('Contact found: ',name), 'Press "YES" to Delete')
			objContact.Delete
		endif
	endif
	ObjectClose(objContact)
Next

; Clean up
ObjectClose(objContactItems)
ObjectClose(objFolder)
ObjectClose(objNameSpace) 
ObjectClose(objOutlook)

exit

Article ID:   W16582
File Created: 2005:02:18:12:21:32
Last Updated: 2005:02:18:12:21:32