Pointing to the different folder

Status
Not open for further replies.
V

Vit

Hello,

I have a macro that looks at my inbox and saves all of the emails as

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 have

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; but

I'm not sure how to modify it to have the script look into a folder

other than the Inbox. I am attempting to look in a folder ("IR") that is

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 If
 
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 sure

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 If

--
 
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 my

needs. Thank you! Bg:)
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Email pointing Using Outlook 2
J How to import many msg into different public folders in Outlook Outlook VBA and Custom Forms 7
J Importing N2K from a different Exchange Server Using Outlook 1
A Automatic forwarding to different people on a rotational basis Using Outlook 2
R Auto Forwarding with different "From" Outlook VBA and Custom Forms 0
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
M Outlook on 3 Computers Shows Different Total Items on Same Account Using Outlook 3
R Microsoft Outlook 2016 - Gmail not sending, asks for password for SMTP, tried different ports Using Outlook 23
V Outlook Forms: Formatting a Label with 2 different styles Outlook VBA and Custom Forms 1
David in Mississippi New (Feb 2020) install of Outlook 365 - Cannot specify PST for different accounts Using Outlook 0
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
T why are the calendar icons different for different accounts Using Outlook 2
E Project Management - Adding Folders for Different Folder Types Using Outlook.com accounts in Outlook 0
O Using .OST and .PST mail thru different providers Using Outlook 5
R Reinstall to a different drive or folder Using Outlook 1
L How to use different fonts for outgoing messages for different email accounts Using Outlook 0
T Categorizing different colors for a series of events Using Outlook 0
N Combined emails on 2 iphones from different email addresses Using Outlook 4
K adding more rules to 'different domains check' macro Outlook VBA and Custom Forms 2
Frédéric Save E mail using different path. Outlook VBA and Custom Forms 24
P Migrate Office 365 mailbox to a different on-premises domain Using Outlook 1
J Why are emails for a different pop account copied to outlook.com account? Using Outlook 1
J Autoforward emails to different contacts based on certain criteria using only one rule Using Outlook 1
S Different alert time for different meetings Using Outlook 1
Diane Poremsky Create Tasks from Email and move to different Task folders Using Outlook 0
oliv- Why custom form is different from original ipm.contact ? Outlook VBA and Custom Forms 4
B Check for different domains macro to be triggered by specific domains only Outlook VBA and Custom Forms 2
Q Form displayed is different from form edited Outlook VBA and Custom Forms 3
T Duplicate emails in different "sent" boxes. Using Outlook 2
R Outlook 2013 VB rule to auto save attachments with different file types Outlook VBA and Custom Forms 5
G Drafts go to a different pst! Using Outlook 1
I Different users connected to an IMAP email aren't syncing with each other Using Outlook 5
K Different kind of issue related to creation of archive after one has been deleted Exchange Server Administration 1
K Outlook 2013 Multi Accounts set Default different calendar Sender Using Outlook 2
M How do I mark emails already received as read when I get a second, different email based on subject? Outlook VBA and Custom Forms 3
E OL2007 on Exchange: opening OL on different computers Using Outlook 1
O Copy email content and paste into new Word Document using a different font Using Outlook 1
J How to sort incoming email that is sent to a different address to my main one? Using Outlook 1
D can you share a bcm database with 2 different versions of windows? BCM (Business Contact Manager) 0
W Moving Exchange 2007 to a different drive/partition? Exchange Server Administration 1
J How to create fields that will use the same value on different record types BCM (Business Contact Manager) 2
S "Search People" sometimes shows contacts 2 different ways - Outlook 2013 Using Outlook 6
C Help with a Macro to move emails to a different PST data file Using Outlook 4
B Excel 2010 vba to post appts to different outlook calendars at the same time Using Outlook 6
M Apply different views to calendars Using Outlook 0
F Sync of 2 calendars from different organization Using Outlook 0
G Opening pst files in different versions of outlook Using Outlook 2
P Different names for the same email address Using Outlook 1
R Different behavior AutoForward with Rule vs manual forward. Using Outlook 0
J Sending Mail From A Different Address Using Outlook 2011 for Mac Using Outlook 0

Similar threads

Top