Solved

Accessing public folders with VBA

Posted on 2000-03-20
5
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

630 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