Problems with code

Status
Not open for further replies.
G

Gustavo Strabeli

Hello!

I'm using below code in order to have Outlook adding email addresses to my

contacts folder.

So here's the problem: adresses are being added to my contacts however it's

inserting quotes before and after the address.

I don't know nothing about VBA, but analysing the code I deleted the Chr(34)

from the code and this problem was solved, however another problem

was raised: now all my contacts are being duplicated.

Do you know how to fix that? I mean, delete the quotes and don't have the

contacts duplicated?

Thanks a lot,

Gustavo

The code:

Sub AddRecipToContacts(objMail As Outlook.MailItem)

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 i As Integer

On Error Resume Next

' 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

' if not, add it

If objContact Is Nothing Then

Set objContact = _

Application.CreateItem(olContactItem)

With objContact

> FullName = objRecip.Name

> Email1Address = strAddress

> Save

End With

End If

Set objContact = Nothing

Next

Set objNS = Nothing

Set objContact = Nothing

Set colContacts = Nothing

End Sub

Function AddQuote(MyText) As String

AddQuote = Chr(34) & MyText & Chr(34)

End Function
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I assume you have a lot of contacts already stored with quotes. Delete all

those contacts and run your code again. Then you should end up only with

addresses without quotes.

Best regards

Michael Bauer

Am Wed, 27 May 2009 11:03:45 -0300 schrieb Gustavo Strabeli:


> Hello!

> I'm using below code in order to have Outlook adding email addresses to my
> contacts folder.
> So here's the problem: adresses are being added to my contacts however


it's
> inserting quotes before and after the address.
> I don't know nothing about VBA, but analysing the code I deleted the


Chr(34)
> from the code and this problem was solved, however another problem
> was raised: now all my contacts are being duplicated.
> Do you know how to fix that? I mean, delete the quotes and don't have the
> contacts duplicated?

> Thanks a lot,

> Gustavo

> The code:

> Sub AddRecipToContacts(objMail As Outlook.MailItem)
> 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 i As Integer
> On Error Resume Next

> ' 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

> ' if not, add it
> If objContact Is Nothing Then
> Set objContact = _
> Application.CreateItem(olContactItem)
> With objContact
> .FullName = objRecip.Name
> .Email1Address = strAddress
> .Save
> End With
> End If
> Set objContact = Nothing
> Next

> Set objNS = Nothing
> Set objContact = Nothing
> Set colContacts = Nothing
> End Sub

> Function AddQuote(MyText) As String
> AddQuote = Chr(34) & MyText & Chr(34)
> End Function

>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R Roadrunner Email Problems | Roadrunner Technical Service Number Outlook VBA and Custom Forms 0
K Outlook for Mac problems Using Outlook 0
V iCloud calendar problems, Outlook shuts down immediately Using Outlook 2
D a general question re how backup programs handle pst files ... I have no problems, just curious Using Outlook 1
A iCloud add in problems Using Outlook 4
V Outlook 2016 Outlook-2016 and iCloud for Windows - Problems Using Outlook 11
M Export-Import .pst file problems Using Outlook 2
V iCloud calendar sync problems Using Outlook 13
T Many problems with outlook.com - will upgrade to Outlook soon Using Outlook 1
cricket1001 Problems with calendar syncing Using Outlook 0
P Syncing problems with add-ins Using Outlook 3
T problems with Contacts Using Outlook 8
P Problems with Standss new Quickfile 6 Using Outlook 3
Q Problems with Autodiscover Outlook 2016 Using Outlook 0
D Outlook 2013 Yahoo IMAP Sync problems Using Outlook 1
M Indexing Problems Outlook 365 Using Outlook 2
M I'm Having problems Moving Contacts to a New List Using Outlook 8
C 2016 Outlook Certificate Problems Outlook VBA and Custom Forms 3
D Archiving Problems Using Outlook 6
M Recent Update Did not Fix Search Problems Using Outlook 7
S Problems syncing emails with webmail after changing to Outlook 2016 Using Outlook 1
crazyboy Problems connecting to BCM on Server Using Outlook 2
J Problems connecting to BCM BCM (Business Contact Manager) 16
O Folder Pane problems Using Outlook 5
M Problems Downloading Content from Server(s) Using Outlook 0
O Outlook 2013 Problems sending large mails Using Outlook 4
Diane Poremsky iCloud and Outlook Problems: Syncing Calendar Using Outlook 0
G Outlook problems Using Outlook 2
D Calendar view problems with reading pane open Using Outlook 0
A Two Problems with BCM BCM (Business Contact Manager) 0
G Problems with Active Directory Rights Management Services (AD RMS) in Outlook 2013 Exchange Server Administration 0
A Problems Opening Excel from Outlook Outlook VBA and Custom Forms 3
T Outlook Connector calendar sync problems with Android phone Using Outlook.com accounts in Outlook 1
J Outlook 2010 sync problems with Outlook Connector Using Outlook 1
B Outlook being closed causing problems during copy to Excel Outlook VBA and Custom Forms 6
A Problems with Outlook Connector in Outlook 2010 Using Outlook 2
V Please help if you can. Problems with Bcc BCM (Business Contact Manager) 3
J problems downloading POP3 emails to Outlook 2003 Using Outlook 1
THOMAS BRAXTON Microsoft Office 2010 problems Using Outlook 1
tswatek Inbox problems after adding MS Exchange email Using Outlook 2
B two unrelated problems Using Outlook 2
Felix Deleted emails sync problems Using Outlook.com accounts in Outlook 1
H Problems With Outlook 2013 VBA To Send and Print an email Outlook VBA and Custom Forms 1
L Outlook 2013 setup problems Exchange Server Administration 1
T Outlook 2013 and outlook.com sync problems Using Outlook 5
R Outlook 2013 email folder sync problems using OneDrive Using Outlook 3
Tim King Message body problems Using Outlook 3
M Outlook problems after yesterday's update Using Outlook 4
Jon Bakrley problems with outlook 2013 and pst files Using Outlook 4
C Outlook 2013 compatibility problems with outlook 2007 Using Outlook 3

Similar threads

Top