Ask a questionAsk a question
 

AnswerOutlook 2003 contacts - change 'File-As' property

  • Wednesday, April 15, 2009 11:59 PMsuznal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I know I can do what I need without VBA, but I really haven't done much with VBA in Outlook and I want some help to get my feet wet.


    I have a few different contact folders in Outlook. Currently the 'file-as' property for the contacts is set to Last Name, First Name Middle Name.
    I would like to run code on each of the contact items in each of the contact folders to switch the File-as property to, First Name, Middle, Last.

    Hope someone can help me!
    "The new phonebooks are here!"

Answers

  • Saturday, April 18, 2009 3:34 PMADG Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code

    Hi,below is some simple code to list all folders and their types to the immediate window. Type 2 denotes a folder holding contacts. Paste the code to a new module and run listfolders .Each folder can have its own folders. so to refer to a sub folder e.g. Contacts will look like - Set myFolder = myNamespace.Folders("Personal Folders").Folders("Contacts"). You can either hardcode your folder names or modify the below to find contact folders. Hope this helps.

    Public Sub ListFolders()
        Dim x As Long
        Dim myOlApp As Outlook.Application
        Dim myNamespace As Outlook.NameSpace
        Dim myFolder As Outlook.MAPIFolder
        Set myOlApp = CreateObject("Outlook.Application")
        Set myNamespace = myOlApp.GetNamespace("MAPI")
        For Each myFolder In myNamespace.Folders
            Debug.Print "level 1", myFolder.Name, myFolder.DefaultItemType
            Call ListSubFolders(myFolder, 1)
        Next
    End Sub
    Public Sub ListSubFolders(myFolder As Outlook.MAPIFolder, lngLvl)
    Dim x As Long
    Dim mySubFolder As Outlook.MAPIFolder
    x = lngLvl + 1
    For Each mySubFolder In myFolder.Folders
            Debug.Print Space(x) & "level " & x, mySubFolder.Name, mySubFolder.DefaultItemType
            Call ListSubFolders(mySubFolder, x)
        Next
    End Sub
    




    Regards

    ADG

    • Marked As Answer bysuznal Tuesday, April 21, 2009 1:11 AM
    •  

All Replies

  • Thursday, April 16, 2009 1:38 AMsuznal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    OK, I found a good example at...

    http://www.slipstick.com/contacts/file-as.htm


    However, I'm having trouble getting it to work for all of my contact folders. It works for the default Contact folder just great, but as usual I am having trouble finding any help in the VBE help files.

    Could someone help me modify the code at the above address to work with other contact folders (For example - I have one called "Work Contacts")
    "The new phonebooks are here!"
  • Friday, April 17, 2009 11:00 PMsuznal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Bump



    Does anyone know how to modify the code (see link in previous reply), for folders other than the default contact folder?
    I have a contact folder called "Work Contacts" that I would like to run the code for.


    "The new phonebooks are here!"
  • Saturday, April 18, 2009 3:34 PMADG Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code

    Hi,below is some simple code to list all folders and their types to the immediate window. Type 2 denotes a folder holding contacts. Paste the code to a new module and run listfolders .Each folder can have its own folders. so to refer to a sub folder e.g. Contacts will look like - Set myFolder = myNamespace.Folders("Personal Folders").Folders("Contacts"). You can either hardcode your folder names or modify the below to find contact folders. Hope this helps.

    Public Sub ListFolders()
        Dim x As Long
        Dim myOlApp As Outlook.Application
        Dim myNamespace As Outlook.NameSpace
        Dim myFolder As Outlook.MAPIFolder
        Set myOlApp = CreateObject("Outlook.Application")
        Set myNamespace = myOlApp.GetNamespace("MAPI")
        For Each myFolder In myNamespace.Folders
            Debug.Print "level 1", myFolder.Name, myFolder.DefaultItemType
            Call ListSubFolders(myFolder, 1)
        Next
    End Sub
    Public Sub ListSubFolders(myFolder As Outlook.MAPIFolder, lngLvl)
    Dim x As Long
    Dim mySubFolder As Outlook.MAPIFolder
    x = lngLvl + 1
    For Each mySubFolder In myFolder.Folders
            Debug.Print Space(x) & "level " & x, mySubFolder.Name, mySubFolder.DefaultItemType
            Call ListSubFolders(mySubFolder, x)
        Next
    End Sub
    




    Regards

    ADG

    • Marked As Answer bysuznal Tuesday, April 21, 2009 1:11 AM
    •  
  • Monday, April 20, 2009 1:11 PMsuznal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    ADG - Thank you.

    I will give it a try tonight.
    "The new phonebooks are here!"
  • Tuesday, April 21, 2009 1:11 AMsuznal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    ADG - Thanks for the help.
    I changed a line from the example code...

    Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)

    to...

    Set objContactsFolder = objNS.Folders("Personal Folders").Folders("Work Contacts")



    It worked!!!
    "The new phonebooks are here!"