Changing Message Class and Journal Values Programmatically

AlecEriksson
AlecEriksson used Ask the Experts™
on
Hi there, this is a question which at first I figured would be simply a matter of exporting my existing 1700 contacts to an Excel sheet and changing the values, and then importing back into Outlook.  Sadly, not the case at all as it turns out certain internal-use fields in Outlook can not be imported/exported.  And so the problem arises...

How do I go about changing the values of the "Message Class" and "Journal" fields for each of 1700 contacts en masse?  

If someone could walk me through this I would greatly appreciate it!

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

Commented:
Hi AlecEriksson,

You can try this Outlook macro.  Follow these instructions to set it up.
1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Modules and click on Module1
4.  Copy the code below and paste it into the right-hand pane of the VB Editor
5.  Click the diskette icon on the toolbar to save the changes
6.  Close the VB Editor
7.  Click Tools->Macro->Security
8.  Change the Security Level setting to Medium
9.  Run the macro.  It will loop through all the contacts in the default contacts folder and adjust the Journal and MessageClass settings to whatever values you want to set them to.  I'd recommend making a backup of the contacts folder before you run this.  I'm suggesting that because changing the MessageClass seems dangerous to me.

Sub ChangeContactProperties()
    Dim olkContacts As Outlook.MAPIFolder, _
        olkContact As Object
    Set olkContacts = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
    For Each olkContact In olkContacts
        If olkContact.Class = olContact Then
            'Set the value to True or False as desired
            olkContact.Journal = True
            'Set the MessageClass to some value
            olkContact.MessageClass = "???"
            olkContact.Save
        End If
    Next
    Set olkContact = Nothing
    Set olkContacts = Nothing
End Sub

Cheers!

Author

Commented:
Is there a way to make it not use the default contacts folder and instead use a folder path?

Something like \Personal Folders\Import Contacts\?  I tried to change it myself and it doesn't like using a string value instead of an object (from what I can gather about vbscript).

Author

Commented:
Oh and I also get an error at the For Each line....

"Object does not support property or method"

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2010
Commented:
AlecEriksson,

> Is there a way to make it not use the default contacts folder and
> instead use a folder path?
Sure.  I've modified the code below to do that.  It will now use the currently selected folder instead of the default folder.  Click on the folder you want to run against, making sure it holds contacts, and then launch the macro.

> Oh and I also get an error at the For Each line....
Sorry, that's my fault.  I left something off the original code.

Sub ChangeContactProperties()
    Dim olkContacts As Outlook.MAPIFolder, _
        olkContact As Object
    Set olkContacts = Application.ActiveExplorer.CurrentFolder
    For Each olkContact In olkContacts.Items
        If olkContact.Class = olContact Then
            olkContact.Journal = True
            olkContact.MessageClass = "???"
            olkContact.Save
        End If
    Next
    Set olkContact = Nothing
    Set olkContacts = Nothing
    MsgBox "All done!", vbOKOnly + vbInformation, "ChangeContactProperties Macro"
End Sub

Author

Commented:
Excellent!  It works, albeit slow.  But that's probably just a function of my 1Ghz system and not so much the macro itself.  Heh.

Many thanks for the help, and the in fact changing the MessageClass to something else worked like a charm to force the record to use a new form as I intended.  Works great actually.  Now to set it and let it run over night!
Top Expert 2010

Commented:
You're welcome.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial