Consulting

Results 1 to 3 of 3

Thread: Solved: Default Folder Problem

  1. #1

    Arrow Solved: Default Folder Problem

    Hi

    In order to refer to my inbox I use
    [VBA]
    Dim ns As NameSpace
    Dim ib As MAPIFolder

    Set ns = ThisOutlookSession.Session
    Set ib = ns.GetDefaultFolder("olFolderInbox")
    [/VBA]

    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
    [VBA]
    Set ib = ns.GetDefaultFolder("olFolderMailbox - Stewart Porteous")
    [/VBA]
    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

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi and welcome to VBAX

    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:[VBA]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")[/VBA] Hope that helps
    K :-)

  3. #3

    Talking ThankYou

    Thanks for the welcome Killian.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •