Solved

Programatic search and replace of contacts/notes field

Posted on 2004-10-13
4
198 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
If you don't know how to downgrade, my instructions below should be helpful.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

12 Experts available now in Live!

Get 1:1 Help Now