Solved

Programatic search and replace of contacts/notes field

Posted on 2004-10-13
4
199 Views
Last Modified: 2010-04-08
Within my contacts list, there was a corruption which has caused a block of text to be put in the notes field of every contact.  There are some 600-odd contacts, so I'm not crazy about doing a manual removal of the text.

I tweaked some code I found to do a search and replace to remove the text (below), but after I ran into problems I realized that the notes field was some sort of rich text field.. so string ops won't work on it.

How can I adapt the code to work on such a field?

Thanks!  joe

Sub cleannotesfield()
 
 Dim strOld         As String
    Dim strNew         As String
    Dim olApp          As Outlook.Application
    Dim olNameSpace    As Outlook.NameSpace
    Dim olFolder       As Outlook.MAPIFolder
    Dim olMatchedItems As Object
    Dim objItem        As Object
    Dim strCriteria, strNotes   As String
    Dim i, ipos As String

 
    strOld = "-----Original Message"
    strNew = ""

    Set olApp = New Outlook.Application
    Set olNameSpace = olApp.GetNamespace("MAPI")
    Set olFolder = olNameSpace.GetDefaultFolder(olFolderContacts)
    'strCriteria = "[Company] = '" & strOld & "'"
    'Set olMatchedItems = olFolder.Items.Restrict(strCriteria)
    'Set olMatchedItems = olFolder.Items.all
    'If olMatchedItems.Count = 0 Then Exit Sub
    For Each objItem In olFolder.Items
        strNotes = objItem.Notes
        ipos = InStr(0, strOld, strNotes)
        If ipos > 0 Then
            strNew = Left(strNotes, ipos - 1)
            i = MsgBox(strNew, vbOKOnly, objItem.FullName)
            'objItem.Notes = strNew
            'objItem.Save
        End If
        'MsgBox (objItem.FullName)
        'objItem.CompanyName = strNew
    Next
End Sub
0
Comment
Question by:jpresto
  • 3
4 Comments
 
LVL 13

Expert Comment

by:stefri
ID: 12302065
use objItem.Body property
stefri
0
 

Author Comment

by:jpresto
ID: 12304754
Thanks - it works - almost.  If I have a notes field with text and a graphic, my sub will remove what I need and keep the graphic, but the text will be stripped of any formatting.

Any way to keep text formatting?

Thanks - joe
0
 
LVL 13

Expert Comment

by:stefri
ID: 12323276
I am afraaid not: the only property for Contact I know is Body which is pure text
I was hoping there was as,for mail item, an HTMLBody but no luck
Stefri
0
 
LVL 13

Accepted Solution

by:
stefri earned 500 total points
ID: 12331560
Check Redemption DLL (http://www.dimastr.com/redemption/) which apparently can access the RTFBody
Check Redemption object Model page
Stefri
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook Free & Paid Tools
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now