Solved

Outlook Command

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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…

709 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now