Solved

Accessing public folders with VBA

Posted on 2000-03-20
5
326 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Find out how to use dynamic social media in email signatures with this top 10 DOs & DON’Ts.
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 …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

707 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

13 Experts available now in Live!

Get 1:1 Help Now