Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Programatic search and replace of contacts/notes field

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
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 …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

597 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