About replacing word/categories in Outlook contacts


J

Jeff

Below is a copy of a thread I started in the Outlook/Contacts forum (in
reverse order) and was told by an MVP that this forum is the correct one for
my current programming question. The paragraph below followed by the code,
then several questions and comments, are my question(s).

----------------------------------------------------------------------------------
Thank you so much for your reply and advice. Using the links you provided I
was able to piece together a macro that did the job. Naturally I want to
improve on it. Below is the macro I used with several lines commented with
two quotes ('') that I would like to make into working parts of the macro but
I don't have the programming knowledge to make that happen. Explanations and
questions follow this macro code:

Sub ChangeCategoryText()
Dim objContactsFolder As Outlook.MAPIFolder
Dim objContacts As Outlook.Items
Dim objContact As Object
Dim iCount, aCount As Integer
Dim strOldCat, strNewCat, strContactFolder As String

' Specify which contact folder to work with
'' strContactFolder = InputBox("Name of contact folder that contains the
category you want to modify.")
'' If strContactFolder = "" Then Exit Sub

Set objContactsFolder = Outlook.ActiveExplorer.CurrentFolder
Set objContacts = objContactsFolder.Items

' Prompt for old and new category names
strOldCat = InputBox("Enter the old category name." & Chr(13) &
"(spelling and capitalization must be exact)")
If strOldCat = "" Then Exit Sub

strNewCat = InputBox("Enter the new category name." & Chr(13) &
"(spelling and capitalization must be exact)")
If strNewCat = "" Then Exit Sub

iCount = 0
aCount = 0
'' MsgBox "Updating categories, please wait..."

' Process the changes
For Each objContact In objContacts
aCount = aCount + 1
If TypeName(objContact) = "ContactItem" Then
If InStr(objContact.Categories, strOldCat) > 0 Then
objContact.Categories = Replace(objContact.Categories,
strOldCat, strNewCat)
objContact.Save
iCount = iCount + 1
'' MsgBox Str$(aCount) & " contacts checked, " & Str$(iCount) &
" updated. Please wait..."
End If
End If
Next

MsgBox Str$(aCount) & " contacts checked, " & Str$(iCount) & " updated."

' Clean up
Set objContact = Nothing
Set objContacts = Nothing
Set objContactsFolder = Nothing
End Sub

1. The first and second lines with two quotes would be a way to select the
folder to be scanned for modification. In this working model the current
default folder is used but the macro would be more flexible if the user could
choose. A way to "pick" the folder from a list of contact folders would be
best.

2. The third and fourth lines with two quotes could serve as status reports
if there is some way to loss the buttons and continue without waiting for
user response. Along with this it would be helpful to disable user input
while the macro is running so as to avoid partial or corrupted changes.

If you know of any ways to accomplish these program modifications please post
here. I can envision a one dialog box solution that would ask for user input
for the three string variables, check for validity of data, and proceed with
regular status reports.

Either way I thank you for your time and attention in helping me with this
seemingly simple, but ultimately complex, category modification
----------------------------------------------------------------------------------

Diane Poremsky said:
No. You can use this method to change categories:
http://www.slipstick.com/outlook/searchreplacecompany.htm
Group by categories, select a group and right click, categories to remove
from that category.

--
Diane Poremsky [MVP - Outlook]



Outlook Tips by email:
mailto:[email protected]

EMO - a weekly newsletter about Outlook and Exchange:
mailto:[email protected]

You can access this newsgroup by visiting
http://www.microsoft.com/office/community/en-us/default.mspx or point your
newsreader to msnews.microsoft.com.


Jeff said:
I would like to replace a word in the Categories field in Contacts with
another word (often known as Find and Replace). In the future I may need
to
do this operation in other fields as well. Is there a way to do this to a
group of records/contacts?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top