Solved

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

Posted on 2016-08-02
6
124 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 81

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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
You deserve ‘straight talk’ from your cloud provider about your risk, your costs, security, uptime and the processes that are in place to protect your mission-critical applications.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

717 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