Solved

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

Posted on 2014-01-18
2
1,089 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

830 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