Solved

Outlook Command

Posted on 2013-12-27
2
282 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
[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
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Read this checklist to learn more about the 15 things you should never include in an email signature.
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…
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: …

739 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