Solved

Programatic search and replace of contacts/notes field

Posted on 2004-10-13
4
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

735 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