A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

About replacing word/categories in Outlook contacts



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old March 16th 09, 02:03 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default About replacing word/categories in Outlook contacts

The easiest way to get a folder is to use the NameSpace.PickFolder() method,
which returns a MAPIFolder object. You can't control it only showing or
allowing selection of Contacts folders, but your handler after the code
returns from PickFolder() can test for MAPIFolder.DefaultItemType =
olContactItem to verify it's a Contacts folder. If not just show an error
message and loop back to the dialog call. That will show a treeview of all
folders, much nicer than having the users spell the folder name correctly.

What I'd do for a categories selection dialog would be to iterate the
contents of the folder (Items collection and get all the categories in all
the items into a collection. That will automatically eliminate duplicate
entries if you set the key of each collection entry to the category value.
That would be placed in a list box to prevent spelling errors, the users
could just select from existing categories values.

Then the new category entries can be made from a textbox.

I'd make the dialog display modally and have it set global values for the
selections when the OK button is clicked.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Jeff" wrote in message
...
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.


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing contacts on a WM 6.1 device with my Outlook contacts chambersbobby Outlook - Using Contacts 1 October 13th 08 01:32 PM
Use categories set up in Outlook 07 to filter Word 07 mail merge? cmccaslin Outlook - Using Contacts 2 June 7th 07 10:49 PM
replacing email addresses in contacts Davidru Outlook - Using Contacts 4 May 3rd 07 09:27 PM
How do I restore my contacts in Outlook 2003 after replacing the . Dewey Outlook - Using Contacts 2 March 29th 06 08:06 PM
Replacing contacts with new file carina Outlook - Using Contacts 1 February 7th 06 01:59 PM


All times are GMT +1. The time now is 02:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.