Solved

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

Posted on 2016-08-02
6
110 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
6 Comments
 
LVL 80

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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In-place Upgrading Dirsync to Azure AD Connect
In the wake of AWS' S3 outage, we want to discuss the importance of storage and data diversification in the event of a hack, crash, or system disruption. We spoke with Experts Exchange’s COO Gene Richardson for a deeper understanding.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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