Pointing to the different folder

V

Vit

Hello,
I have a macro that looks at my inbox and saves all of the emails a
HTML and attachments to a specific folder. The problem I have with this
macro is that I cannot figure out a way to point that macro at another
folder, other than the default inbox.
I would like to have the macro look into another shared mailbox I hav
under my account. Here's what I think points the macro into my default
inbox folder:

Dim inBox As Outlook.MAPIFolder

Set inBox = Me.ActiveExplorer(). _
Session.GetDefaultFolder(Outlook.OlDefaultFolders _
.olFolderInbox)

The team mailbox would be "TCW" and the folder would be "IR".
Thank you in advance
 
K

Ken Slovak - [MVP - Outlook]

What you need is NameSpace.GetSharedDefaultFolder(). You supply it with the
alias and folder.

If the mailbox is already loaded in your profile on startup you can iterate
the Stores collection in Outlook 2007 and find that mailbox (Store) and get
the folder using Store.Folders.Item("IR"). If this is Outlook 2003 or
earlier it would be NameSpace.Folders.Item("IR"). That's assuming the folder
is at the same hierarchical level as Inbox.
 
V

Vit

I found this code on another forum which was written by you, Ken; bu
I'm not sure how to modify it to have the script look into a folde
other than the Inbox. I am attempting to look in a folder ("IR") that i
on the same hierarchical level as Inbox. Here's the code:

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

Set oNS = Application.GetNamespace("MAPI")
Set oRecip = oNS.CreateRecipient("TCW")
oRecip.Resolve
If oRecip.Resolved Then
Set inBox = oNS.GetSharedDefaultFolder(oRecip, olFolderInbox)
Set oSubFolder = inBox.Folders("IR")
Set inBox = Store

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

Ken Slovak - [MVP - Outlook]

You cannot use GetSharedDefaultFolder() to get at anything but a default
folder. If your custom folder is under Inbox say, you can get Inbox using
that method and then get Inbox.Folders.Item("whateverName"), but if it's at
the same hierarchical level as Inbox then you wouldn't be able to do that
and you'd have to use the other method I indicated.
 
V

Vit

Ok, so to implement the method that you mentioned earlier, I'm not sur
what do I need to change in this code. Can you please give me a tip
Thank you!:)


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

Set oNS = Application.GetNamespace("MAPI")
Set oRecip = oNS.CreateRecipient("TCW")
oRecip.Resolve
If oRecip.Resolved Then
Set inBox = oNS.NameSpace.Folders.Item("NAV")
Set inBox = Store

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

Ken Slovak - [MVP - Outlook]

Since you never mentioned where in the tree hierarchy of that mailbox the
folder of interest is I can't really show you code that's definitely
appropriate.

Assuming the folder is a top level folder at the same level as Inbox you'd
use something like this:

Dim oNS As Outlook.NameSpace
Dim TCW As Outlook.MAPIFolder
Dim IR As Outlook.MAPIFolder

Set oNS = Application.GetNamespace("MAPI")
Set TCW = oNS.Folders.Item("Mailbox - TCW")
Set IR = TCW.Folders.Item("IR")

That assumes the other mailbox is being opened as part of your Outlook
profile, otherwise the code wouldn't work.
 
V

Vit

YAY, it worked.... I was able to customize that code snippet to fit m
needs. Thank you! Bg:
 

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