Want to add code to ThisOutlookSession, but other code already exists

N

NatDev

Hi,

I want to add the VBA code mentioned in the first part of this link t
my Outlook 2003: http://www.outlookcode.com/article.aspx?id=72

The problem that I am running into is that I already have some code i
my ThisOutlookSession that I would like to keep and if I just plop thi
code in before the other code, this new code doesn't work. If I dro
the code mentioned in the link above into an empty ThisOutlookSession o
another machine, it works fine. I am probably missing some simple step
but do very little with VBA in Outlook and have been unable to find wha
I am looking for by Googling.

Here is the code that I already have in place. I believe it doe
something with the setup of my Outlook Contacts. Again, my goal is t
have the code below continue to work plus the code in the first part o
the link above:

Public Sub ChangeFileAs()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objContact As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim objContactsFolder As Outlook.MAPIFolder
Dim obj As Object
Dim strFirstName As String
Dim strLastName As String
Dim strCompanyName As String
Dim strFileAs As String

On Error Resume Next

Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactsFolder.Items

For Each obj In objItems
'Test for contact and not distribution list
If obj.Class = olContact Then
Set objContact = obj

With objContact
strFirstName = .FirstName
strLastName = .LastName
strCompanyName = .CompanyName
strFileAs = strCompanyName & " " & "(" & strLastName
", " & strFirstName & ")"
.FileAs = strFileAs
.Save
End With
End If

Err.Clear
Next

Set objOL = Nothing
Set objNS = Nothing
Set obj = Nothing
Set objContact = Nothing
Set objItems = Nothing
Set objContactsFolder = Nothing
End Sub

Any help would be appreciate.

Thanks
 
K

Ken Slovak - [MVP - Outlook]

There's no reason at all why if you used method 1 at your link that it would
interfere with your running that macro to re-order your contact filing. Both
pieces of code can co-exist.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top