Referencing a particular email box via VBA

G

GLT

Hi,

I am trying to import messages from a shared email box (not my own).

Currently I have the shared email box open up when outlook starts.

This code is what I execute to import messages:

' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim c As Outlook.MailItem
Dim objItems As Outlook.Items
Dim objFolder As Outlook.MAPIFolder

FolderName = "ResultsFolder"
Set olns = ol.GetNamespace("MAPI")
Set objFolder = olns.GetDefaultFolder(olFolderInbox).Folders(FolderName)
Set objItems = objFolder.Items

I would like anyone of my team members to be able to execute this code and
the messages are imported from the shared email box.

How do I reference a particular email box (email box name: SharedTeam) in
the code above?

Cheers,
GLT.
 
K

Ken Slovak - [MVP - Outlook]

Look at the Object Browser Help on the NameSpace.GetSharedDefaultFolder()
method.
 
G

GLT

Hi Ken,

Thanks for your reply,

I tried using this and unfortuanetly I cannot get this working.

I still need to get my team members to add this email box to their profiles
in order for it to work.

Is there a way that people can execute VBA code without having to add the
users email box to their profiles (ie via the control panel).

Can you point me to any particaulr examples of this?

Cheers,
GLT
 
K

Ken Slovak - [MVP - Outlook]

It should be pretty simple. If the shared mailbox name is "SharedTeam" then
something like this should work:

Dim oRecip As Outlook.Recipient
Dim oFolder As Outlook.MAPIFolder
Dim oNS As Outlook.NameSpace
Dim oSubFolder As Outlook.MAPIFolder

Set oNS = Application.GetNamespace("MAPI")
Set oRecip = oNS.CreateRecipient("SharedTeam")
oRecip.Resolve
If oRecip.Resolved Then
Set oFolder = oNS.GetSharedDefaultFolder(oRecip, olFolderInbox)
Set oSubFolder = oFolder.Folders("Foobar Contacts")

If Not (oSubFolder Is Nothing) Then
MsgBox "Item 1 = " & oSubFolder.Items.Item(1).Subject
Else
MsgBox "Could not get folder"
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top