Solved

How do I create a subfolder in Outlook from an Excel VBA application ?

Posted on 2014-01-18
2
1,008 Views
Last Modified: 2014-01-19
Hi All,

I have an Excel VBA application in which I open Outlook and create a folder. However, I would like to create a subfolder from the main folder but don't seem to be able to do so. Can anyone help ? My current code is below....

   Answer = MsgBox("Create a new Outlook folder ?", vbYesNoCancel)
   
   If Answer = vbYes Then
      OutlookFolderName = teOrderNo & " " & coClientName & " - " & coHeading
      
      Set ol = CreateObject("Outlook.Application")
      Set ns = ol.GetNamespace("MAPI")
      ParentFolder = "Personal Folders"
      MainFolder = "_Toco Orders"
      Set fl = ns.Folders.Item(ParentFolder).Folders.Item(MainFolder)
      fn = OutlookFolderName
   
      If Len(fn) > 0 Then
         Set mf = fl.Folders.Add(fn)
         Set mf = Nothing
         Set fl = Nothing
         Set ns = Nothing
         Set ol = Nothing
         MsgBox "A new Outlook folder has been created successfully", vbInformation
      End If
            
   End If

Open in new window


Many thanks
Toco
0
Comment
Question by:Tocogroup
2 Comments
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 39790988
Well here is how to add a folder:

' Create a new mail folder named "Important Items".
Set fl = ns.Folders.Item(ParentFolder).Folders.Item(MainFolder).Folders.Add("Important Items")


gowflow
0
 

Author Closing Comment

by:Tocogroup
ID: 39791907
Ah yes. That's great. Many thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Outlook Free & Paid Tools
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

760 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

20 Experts available now in Live!

Get 1:1 Help Now