?
Solved

Outlook exchange Office 365 - Add a Subfolder to a "non'Default Folder"

Posted on 2016-08-02
6
Medium Priority
?
162 Views
Last Modified: 2016-08-20
I found this code to add a subfolder to the inbox default folder

 Sub AddInboxProjectsSubFolder()
    Dim olApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim olFolder As Outlook.MAPIFolder
    Dim olNewFolder As Outlook.MAPIFolder
    Dim msg As Outlook.MailItem
   
    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolder = objNS.GetDefaultFolder(olFolderInbox)

    Set olNewFolder = olFolder.Folders.Add("16043 Fuel Island Repair")

End Sub


The attached .pdf shows my outlook folder structure and I would like to adapt this code to add subfolders to the Projects folder

Using Outlook exchange with office 365
0
Comment
Question by:rogerdjr
  • 2
  • 2
5 Comments
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 41740413
no attachment
0
 

Author Comment

by:rogerdjr
ID: 41740639
Not sure what happened


What I want to do is add  subfolders to the Projects folder rather than the inbox
C--Users-Roger-Documents-Outlook-Fol.JPG
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 41763980
msdn...  for GetDefaultFolder  
Remarks
To return a specific non-default folder, use the Folders collection.

    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")
  '--- need to trap error if not exist
    Set olFolder = objNS.Folders("Projects")
   if(err.number>0) then
         Set olFolder = objNS.Folders.Add("Projects")
   end if
   newfoldername = "16043 Fuel Island Repair"
    Set olNewFolder = olFolder.Folders.Add(newfoldername )

Open in new window

0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 2000 total points
ID: 41764004
actually Slipstick seems to recommend..
    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolderTop = objNS.GetDefaultFolder(olFolderInbox).Parent  'get parent of inbox
  '--- need to trap error if not exist
    Set olFolder = olFolderTop.Folders("Projects")
   if(err.number>0) then
         Set olFolder = olFolderTop.Folders.Add("Projects")
   end if
   newfoldername = "16043 Fuel Island Repair"
    Set olNewFolder = olFolder.Folders.Add(newfoldername )

Open in new window

1
 

Author Closing Comment

by:rogerdjr
ID: 41764069
Great solution - thanks for the help
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question