A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 7th 10, 04:29 PM posted to microsoft.public.outlook.program_vba
NatDev
external usenet poster
 
Posts: 1
Default Want to add code to ThisOutlookSession, but other code already exists


Hi,

I want to add the VBA code mentioned in the first part of this link to
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 in
my ThisOutlookSession that I would like to keep and if I just plop this
code in before the other code, this new code doesn't work. If I drop
the code mentioned in the link above into an empty ThisOutlookSession on
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 what
I am looking for by Googling.

Here is the code that I already have in place. I believe it does
something with the setup of my Outlook Contacts. Again, my goal is to
have the code below continue to work plus the code in the first part of
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,


--
NatDev
http://forums.slipstick.com

Ads
  #2  
Old May 7th 10, 04:40 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Want to add code to ThisOutlookSession, but other code already exists

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"NatDev" NatDev.4aliny@invalid wrote in message
news:NatDev.4aliny@invalid...

Hi,

I want to add the VBA code mentioned in the first part of this link to
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 in
my ThisOutlookSession that I would like to keep and if I just plop this
code in before the other code, this new code doesn't work. If I drop
the code mentioned in the link above into an empty ThisOutlookSession on
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 what
I am looking for by Googling.

Here is the code that I already have in place. I believe it does
something with the setup of my Outlook Contacts. Again, my goal is to
have the code below continue to work plus the code in the first part of
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,


--
NatDev
http://forums.slipstick.com


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Archive code -- modify my code! Ray[_5_] Outlook and VBA 3 November 17th 09 10:16 PM
Using VBA code in ThisOutlookSession - Can I send an email asynchronously? Steve[_3_] Outlook and VBA 3 August 31st 07 07:41 AM
Outlook 2007 - Code in ThisOutlookSession Stops Working [email protected] Outlook and VBA 8 August 9th 07 08:02 PM
ThisOutlookSession - code runs only once Rafael1119 Outlook and VBA 8 July 17th 06 12:51 PM
Vba Project OTM - Thisoutlooksession(code) error XP User Outlook and VBA 4 May 7th 06 04:31 PM


All times are GMT +1. The time now is 09:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.