Solved

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

Posted on 2016-08-02
  • Outlook
  • Exchange
  • Email Servers
  • MS Office
  • Office / Productivity
  • +2
6
76 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 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
no attachment
0
 

Author Comment

by:rogerdjr
Comment Utility
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)
Comment Utility
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
Comment Utility
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
Comment Utility
Great solution - thanks for the help
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
If you don't know how to downgrade, my instructions below should be helpful.
Microsoft Office Picture Manager has a Picture Shortcuts pane that shows a list with the Recently Browsed folders. While creating my video Micro Tutorial here at Experts Exchange showing How to Install Microsoft Office Picture Manager in Office 2013…
This video discusses moving either the default database or any database to a new volume.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now