?
Solved

Programatic search and replace of contacts/notes field

Posted on 2004-10-13
4
Medium Priority
?
205 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 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