Solved

Outlook Command

Posted on 2013-12-27
2
279 Views
Last Modified: 2013-12-31
Was looking for some code to add a Receipent to the Contacts List, and changing it up a bit to have some code that would add the Sender to the Contacts List with a category color attached to it.   However, in "blowing off" some old code, this one seemed to fit the Receiptent portion of what was needed, but it keeps erroring out on: "AddQuote."

Sub AddRecipToContacts()
    Dim strFind As String
    Dim strAddress As String
    Dim objNS As Outlook.NameSpace
    Dim colContacts As Outlook.Items
    Dim objContact As Outlook.ContactItem
    Dim objRecip As Outlook.Recipient
    Dim objMail As Outlook.MailItem
    Dim i As Integer
    On Error Resume Next

    If TypeName(Application.ActiveWindow) = "Explorer" Then
        Set objMail = Application.ActiveExplorer.Selection(1)
    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then
        Set objMail = Application.ActiveInspector.CurrentItem
    Else
        Exit Sub
    End If
    ' get Contacts folder and its Items collection
    Set objNS = Application.GetNamespace("MAPI")
    Set colContacts = _
      objNS.GetDefaultFolder(olFolderContacts).Items

    ' process message recipients
    For Each objRecip In objMail.Recipients
        ' check to see if the recip is already in Contacts
'-----------------------------------------
        strAddress = AddQuote(objRecip.Address)
 '-----------------------------------------     

         For i = 1 To 3
            strFind = "[Email" & i & "Address] = " & _
                      strAddress
            Set objContact = colContacts.Find(strFind)
            If Not objContact Is Nothing Then
                Exit For
            End If
       Next

Open in new window

Does AddQuote belong to an object in the Reference Library, which is not loaded, or is this code for a 2007 version and AddQuote is no longer part of object model?  If not what would take it's place?
0
Comment
Question by:Cook09
2 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 39743190
Addquote is an oft used USER DEFINED function to simply add a quote keeping the text block tidyas such the original code may have used a different form but I would expect something like:

Function addQuote(str As String)
    addQuote = Chr(34) & str & Chr(34)
End Function

Open in new window

add this to the end of your code and hopefully!

Chris
0
 

Author Comment

by:Cook09
ID: 39749112
Hi Chris,

Yes, that is what it referred to in this situation.   However, what it provides I can't use, so I had to change the objects around to display what I needed.  But, this cleared the bottleneck.

Thanks...Cook
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

If you don't know how to downgrade, my instructions below should be helpful.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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