PDA

View Full Version : Solved: Default Folder Problem



ScriptHam
04-27-2005, 06:46 AM
:hi: Hi :hi:

In order to refer to my inbox I use

Dim ns As NameSpace
Dim ib As MAPIFolder

Set ns = ThisOutlookSession.Session
Set ib = ns.GetDefaultFolder("olFolderInbox")


In my case Inbox is a subfolder of "Mailbox - FirstName LastName"
As are Outbox, SentItems, Drafts and others which I have created e.g.
1P396, 4P446, BREC-General. These last are specific project files.

I would like to refer to these folders but

Set ib = ns.GetDefaultFolder("olFolderMailbox - Stewart Porteous")

Does not work

Do I have to move my project files into Inbox or is there a way of referring to them?

Help please.
ScriptHam

Killian
04-27-2005, 07:20 AM
Hi and welcome to VBAX :hi:

First, I should point out that you don't need the quotes unless you're referring to a folder's name - olFolderInbox is a VBA constant.
But that also kind of answers your question, since you can refer to the namespace's folders collection and select the item by name:Dim ns As Outlook.NameSpace
Dim ib As MAPIFolder
Dim TargetFolder1 As MAPIFolder
Dim TargetFolder2 As MAPIFolder
Dim TargetFolder3 As MAPIFolder

'set the namespace
Set ns = Application.GetNamespace("MAPI")
'set your inbox
Set ib = ns.GetDefaultFolder(olFolderInbox)
'set your target folder
Set TargetFolder1 = ns.Folders.Item("1P396")
Set TargetFolder2 = ns.Folders.Item("BREC-General")
'you may need to driil down some levels
Set TargetFolder3 = ns.Folders.Item("1P396").Folders.Item("A Sub Folder of 1P396") Hope that helps

ScriptHam
04-27-2005, 07:33 AM
Thanks for the welcome Killian. :beerchug:
And thanks a great deal for the code especially as it was so quick.

I don't fully understand it being a newbie but I think your answer just about wraps it up. I can use the code almost as it is and then ponder over how and why it works another time.

Many thanks to you.
ScriptHam :thumb