Solved

Accessing public folders with VBA

Posted on 2000-03-20
5
327 Views
Last Modified: 2010-04-08
How can I access a public folder to populate a contact list?  I have added the following code
Set cf = OpenMAPIFolder("\Public Folders\All Public Folders\MIS\Test\Address Book")

but the contacts always end up in my default mailbox contact folder.
0
Comment
Question by:toboyle
  • 4
5 Comments
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 2638470
You might like this function better. ;)

Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder
    Dim objFldr As MAPIFolder
    Dim strDir As String
    Dim strName As String
    Dim i As Integer
    On Error Resume Next
    If Left(strPath, Len("\")) = "\" Then
            strPath = Mid(strPath, Len("\") + 1)
    Else
            Set objFldr = Application.ActiveExplorer.CurrentFolder
    End If
    While strPath <> ""
            i = InStr(strPath, "\")
            If i Then
                strDir = Left(strPath, i - 1)
                strPath = Mid(strPath, i + Len("\"))
            Else
                strDir = strPath
                strPath = ""
            End If
            If objFldr Is Nothing Then
                Set objFldr = Application.GetNamespace("MAPI").Folders(strDir)
            On Error GoTo 0
            Else
                Set objFldr = objFldr.Folders(strDir)
            End If
    Wend
    Set OpenMAPIFolder = objFldr
End Function

0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 2638550
Oops... fogot to add something.

Once you get your reference to the public folder from the function above or your own custom routine, you need to use the the Add method of the Items.  So your code becomes.

Set cf = OpenMAPIFolder ("...")
Set myContact = cf.items.add (olcontactitem)


I finished now.  ;)
0
 

Author Comment

by:toboyle
ID: 2642544
I added your function but the import still goes to my default contact folder, not the public folder.  I know I must be missing something.  Has you got your code to work?
0
 
LVL 16

Accepted Solution

by:
Neo_mvps earned 200 total points
ID: 2642782
The function that I supplied will get you a reference to a public folder that you ask for.  The "oops" part is what puts the item in the folder you specify.


So...


Set cf = OpenMAPIFolder("\Public Folders\All Public Folders\MIS\Test\Address Book")

Set myContact = cf.items.add (olcontactitem)
myContact.Display

Sorry about the answer being in two parts.

Note: Tested and works under OL2K

0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 2659607
I have one other idea for you.  The Contact Item has a method named Move.  You could easily save it and then w/out destroying the reference move the item to the public folder.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ost file to pst 10 107
OUTLOOK, KERBERO, NTLM 1 29
Stop users moving/deleting folders in shared mailbox Exchange 2007 3 21
Outlook 2010 public folders 1 7
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Find out what you should include to make the best professional email signature for your organization.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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 …

920 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

16 Experts available now in Live!

Get 1:1 Help Now