none
Add MyOwn Folder under the InBox Folder RRS feed

  • Question

  • Hi!

    I must add a new SubFolder under the InBox.

    I can read the SubFolders under the Inbox.

    But i can not "Add" a new SubFolder under the Inbox Folder!?

    Hav anyone an idea or a short sample for me?

    --> Outlook 2010

    Best Regards

    Bernd

    Thursday, March 19, 2015 11:51 AM

Answers

  • Hello Bernd,

    Have you tried to run the sample code listed above? Does it work?

    > With the MyFolders i can read all SubFolders with "Items"...

    The Items property of the Folder class returns an Items collection object as a collection of Outlook items in the specified folder. But the Folders property returns the Folders collection that represents all the folders contained in the specified Folder.

    > I become an error -65537 when i will add a new Folder!?

    What line of code generates an error in the code? Could you be more specific?

    • Marked as answer by Bernd Riemke Tuesday, March 31, 2015 9:05 AM
    Thursday, March 19, 2015 2:50 PM

All replies

  • Hello Bernd,

    > But i can not "Add" a new SubFolder under the Inbox Folder!?

    Do you get any error message or exception in the code? What code do you use?

    The Outlook Object Model provides the Add function of the Folders class which creates a new folder in the Folders collection. For example:

    Sub AddFolders() 
     Dim myNameSpace As Outlook.NameSpace 
     Dim myFolder As Outlook.Folder 
     Dim myNotesFolder As Outlook.Folder 
     Dim myContactsFolder As Outlook.Folder 
     Dim myPublicFolder As Outlook.Folder 
     
     Set myNameSpace = Application.GetNamespace("MAPI") 
     Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks) 
     On Error GoTo ErrorHandler 
     Set myNotesFolder = myFolder.Folders.Add("Notes Folder", olFolderNotes) 
     Set myContactsFolder = myFolder.Folders.Add("Contacts Folder", olFolderContacts) 
     Set myPublicFolder = myFolder.Folders.Add("Public Folder", olPublicFoldersAllPublicFolders) 
     Exit Sub 
    ErrorHandler: 
     MsgBox "This folder already exists!" 
     Resume Next 
    End Sub
    

    You may also find the How To: Create a new folder in Outlook article helpful.

    Thursday, March 19, 2015 12:10 PM
  • Ok...

    at first i go on with "GetDefaultFolder" from the InboxFolder there i becom an object back e.g. aktFolder

    With the aktFolder i can get the Folders there i become hacj an object eg. MyFolders

    With the MyFolders i can read all SubFolders with "Items"...

    So i can find out is the Folder there or not..

    So far so good :-)

    But i can not add a new Folder if i use the aktFolder object then i become back that is a wrong call

    If i use the MyFolders object then i become back that it is an Array and you can not add there something

    I work with the MAPI calls...

    Thursday, March 19, 2015 12:34 PM
  • I become an error -65537 when i will add a new Folder!?
    Thursday, March 19, 2015 1:45 PM
  • Bernd,

    Please post the code that you are using which generates the error.

    Thursday, March 19, 2015 1:57 PM
  • set InboxFolder = Application.Session.GetDefaultFolder(olFolderInbox)
    set subfolder = Inbox.Folders.Add("my greatest folder ever")
    

    Make sure the folder with that name does not yet exist.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, March 19, 2015 2:35 PM
  • MAPIFolder.Items returns the items in the folder. You need MAPIFolder.Folders collection.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by L.HlModerator Tuesday, March 31, 2015 8:50 AM
    • Unmarked as answer by L.HlModerator Tuesday, March 31, 2015 9:30 AM
    Thursday, March 19, 2015 2:36 PM
  • Hello Bernd,

    Have you tried to run the sample code listed above? Does it work?

    > With the MyFolders i can read all SubFolders with "Items"...

    The Items property of the Folder class returns an Items collection object as a collection of Outlook items in the specified folder. But the Folders property returns the Folders collection that represents all the folders contained in the specified Folder.

    > I become an error -65537 when i will add a new Folder!?

    What line of code generates an error in the code? Could you be more specific?

    • Marked as answer by Bernd Riemke Tuesday, March 31, 2015 9:05 AM
    Thursday, March 19, 2015 2:50 PM
  • I found my Bug!

    Yes it was the Folder Collection!

    Many Thanks all!!!

    Best regards

    Bernd

    Tuesday, March 31, 2015 9:04 AM