Solved

Outlook Command

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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.
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…
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…

828 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