none
OUTLOOK 2010 How to access subfolders in vba

    Question

  • I have the following code and it fails on last line.  It runs fine in Access 2003 but not acess 2010.  I have tried using it from Outlook and still I can only navigate to the inbox and not the subfolder.  Any suggestions....THANKS!

    Set Olapp = CreateObject("Outlook.Application")
        Set Olmapi = Olapp.GetNamespace("MAPI")
        Set myRecipient = Olmapi.CreateRecipient("TEST")
          '  Set myRecipient = Olmapi.CreateRecipient("USERNAME")
             Set OlfolderIn = Olmapi.GetSharedDefaultFolder(myRecipient, olFolderInbox)
        Set Olfolder = OlfolderIn.Folders("Subfolder") ----CANT FIND THE FOLDER.

    Monday, September 26, 2011 4:12 PM

Answers

  • Can you try to install Redemption and try the following code (you can run it from OutlookSpy inside Outlook if you click the Script Editor button):

     

      set Session = CreateObject("Redemption.RDOSession")
      Session.MAPIOBJECT = Application.Session.MAPIOBJECT
      Set OlfolderIn = Session.GetSharedDefaultFolder("TEST", olFolderInbox)
      Debug.Print OlfolderIn.Folders.Count
      Set Olfolder2 = OlfolderIn.Folders("Subfolder")
      Debug.Print TypeName(Olfolder2)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Tuesday, September 27, 2011 4:58 PM

All replies

  • Hello,

    Check if OlfolderIn.FolderPath retruns the correct path (the one your are looking for). I suppose you actually need to call Set OlfolderIn = Olmapi.GetDefaultFolder(olFolderInbox). If my assumption is incorrect and you really need to call GetSharedDefaultFolder, then the Subfolder doesn't exists.


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Monday, September 26, 2011 4:39 PM
  • Do you actually have access to that subfolder? Can you make sure the relevanit user is added to the Permissions tab of that subfolder?
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Monday, September 26, 2011 5:19 PM
  • I checked it and it does go to the correct inbox.  I have multiple inboxes so I have to specify the recipient to direct it to the correct mailbox.  Only problem is when I go to the subfolder.  Weird thing is I have two mailboxes with identical settings and it works for one of them and not the other.  Also, I tried using my colleagues desktop and it didnt find subfolders for both the mailboxes.  So I cant figure out why is it that sometimes it will navigate to a subfolder and other times it wont.  Also, I have made sure that both the subfolders exist and have mail in them.

    Thanks.

    Monday, September 26, 2011 6:01 PM
  • I have created those folders and have full access to them.  We just migrated to office 2010 and we have shared mailboxes...some users have complained of missing folders...I wonder if that has anything to do with it eventhough I am able to see and manipulate the subfolders.
    Monday, September 26, 2011 6:39 PM
  • Can you try to install Redemption and try the following code (you can run it from OutlookSpy inside Outlook if you click the Script Editor button):

     

      set Session = CreateObject("Redemption.RDOSession")
      Session.MAPIOBJECT = Application.Session.MAPIOBJECT
      Set OlfolderIn = Session.GetSharedDefaultFolder("TEST", olFolderInbox)
      Debug.Print OlfolderIn.Folders.Count
      Set Olfolder2 = OlfolderIn.Folders("Subfolder")
      Debug.Print TypeName(Olfolder2)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Tuesday, September 27, 2011 4:58 PM
  • I tried the above solution and I get Run-time error '440':

    Property is read-only.

    For line: 

    set Session = CreateObject("Redemption.RDOSession")

    any suggestions?

    Thanks!

     

     

    Friday, October 07, 2011 3:00 PM
  • Where is your code running? If it is Access VBA, it has an intrinsic variable named "Session".

    Try to change the name to something different:

     

    set MyRdoSession = CreateObject("Redemption.RDOSession")


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/
    OutlookSpy - Outlook, CDO
    and MAPI Developer Tool
    Friday, October 07, 2011 3:01 PM
  • That does get rid of the error message but it still does not navigate to the subfolder.   I can see the subfolders and I have assigned myself as the owners of these folders and still vba doesnt pick up the folders.  I do have multiple mailboxes and when I run this code in my mailbox it does see the subfolders but when I run it in other mailboxes it only navigates to inbox and doesnt even recognize the subfolders.

    I cant figure out why?

     

    Friday, October 07, 2011 5:58 PM
  • "does not navigate to the subfolder" - do you get an error?
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/
    OutlookSpy - Outlook, CDO
    and MAPI Developer Tool
    Friday, October 07, 2011 6:35 PM
  • Well the error message from my code is

    Run-time error '-2147221233(8004010f)'

    The attempted operation failed.  An object could not be found.

     

    If I run your code it just prints 0 for the count and nothing for the subfolder.

    Friday, October 07, 2011 6:52 PM
  • The error is MAPI_E_NOT_FOUND, which means the subfodler with that name does not exist or is invisible to the current user.

    Do you see the current user on the Permissions tab of that subfolder?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/
    OutlookSpy - Outlook, CDO
    and MAPI Developer Tool
    Monday, October 10, 2011 6:46 AM
  • Yes..I see my name in the permissions tab.  I have also noticed that if I log into this mailbox it always sees the folder but if I have multiple mailboxes open it only navigates to the inbox and cant see the subfolders even though they are visible and accessible in outlook.
    Tuesday, October 11, 2011 1:04 PM
  • How do you open the mailboxes? Do you add them to the "Open these additional mailboxes" list on the Advanced tab of the Exchange account properties dialog?
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Thursday, October 13, 2011 3:13 PM
  • Sorry for the delay in reply.  That is exactly how the mailboxes are opened.

    Wednesday, October 19, 2011 2:39 PM
  • So these additional delegate mailboxes do not show subfolders when added  to the "Open these additional mailboxes" list, right?

    What are the security settings on the Inbox folder itself?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Thursday, October 20, 2011 10:22 PM
  • I can see the subfolders in the mailboxes...I just cant navigate to them through vba and manipulate the contents.....
    Monday, October 24, 2011 2:43 PM
  • Do you see thr subfolders when you log in as the primary mailbox owner?

    Or when you open them as delegate mailboxes?

    Or both?

     


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Monday, October 24, 2011 8:35 PM
  • Both.  I can see the folders when logged in as primary or when opened individually....

     

    Wednesday, October 26, 2011 12:37 PM
  • When you open the mailbox as a delegate mailbox, can you click select the Inbox, click Folder button on the OutlookSpy toolbar, then expand to Folders | Count? Do you see 0?
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Thursday, October 27, 2011 9:32 PM
  • I see 2...

    Thank you for taking time to help me with this.

    Wednesday, November 02, 2011 2:16 PM
  • What does the following script display in OutlookSpy (click Script Editor, paste the script, click Run)?

     

    set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    Set OlfolderIn = Session.GetSharedDefaultFolder("TEST", olFolderInbox)
    Debug.Print OlfolderIn.Folders.Count
    Set Olfolder2 = OlfolderIn.Folders("Subfolder")
    Debug.Print TypeName(Olfolder2)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Friday, November 04, 2011 6:00 PM
  • I ran the script and updated to reflect my mailbox and subfolder in it...It does not recognize the subfolders..eventhough I see it under the mailbox.

    0
    Nothing

    Friday, November 04, 2011 6:39 PM
  • I ran the script from my outlook mailbox..and it doesnt recognize the folders.  But if I logged into the outlook using the other mailbox name it does recognize that there are 2 subfolders but the typename is same...

    2
    RDOFolder2

    Friday, November 04, 2011 6:51 PM
  • So it does sound like a permission issue.

    Can you post the screenshot of the Permissions tab for the Inbox folder of that mailbox?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Saturday, November 05, 2011 3:49 PM
  • In order to navigate directly to a subfolders you can use  GetFolderFromID("EntryID")

    Set Olfolder  = olapp.GetNamespace("Mapi").GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A0300C")

     Use the following code to find "Folder ID" 

    Sub GetFoldersEntryID()
       Dim olfolder As Outlook.MAPIFolder
       Dim olapp As Outlook.Application
       Set olapp = CreateObject("Outlook.Application")
       Set olfolder = olapp.GetNamespace("MAPI").PickFolder
       Debug.Print olfolder.EntryID
     End Sub

     

     

    Saturday, January 28, 2012 9:49 PM