Solved

How do I create a new Outlook folder from Excel ?

Posted on 2013-11-09
11
258 Views
Last Modified: 2013-11-10
Hi,

I would like to create a new named Outlook folder from within my Excel 2010 application.

The folder name will be input by the user and appended to the following Outlook folder structure :

Personal Folders/Orders/

I'm not sure where to begin with this.

Thanks
Toco
0
Comment
Question by:Tocogroup
  • 6
  • 4
11 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 39636637
Try this, it is based on an example here
http://social.msdn.microsoft.com/Forums/en-US/768649d6-be9a-4543-ba0a-9c0a31f1aa7b/working-with-outlook-public-folders-from-excel

Dim OL As Outlook.Application
Dim NS As NameSpace
Dim APFs As MAPIFolder      'All Public Folders
Dim MYPF1 As MAPIFolder  'My Pub Folder 1
Dim NewItem As PostItem
  
Set OL = CreateObject("Outlook.Application")
Set NS = OL.GetNamespace("MAPI")
Set APFs = NS.Folders("Public Folders").Folders("All Public Folders")

  ' Enter a valid Public Folder Name below
Set MYPF1 = APFs.Folders("Orders")

MYPF1.folders.Add("Test")

Open in new window

0
 

Author Comment

by:Tocogroup
ID: 39636660
I'm getting a 'User-defined type' error at run-time. Please see attached screenshot.
0
 

Author Comment

by:Tocogroup
ID: 39636661
Let's try uploading the file this time
Create-OL-folder-screenshot.jpg
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 39

Expert Comment

by:als315
ID: 39636678
Look at sample
You will need some libraries in your project (Tools-References in VBA Editor):
referencesAddFolder.xlsm
0
 

Author Comment

by:Tocogroup
ID: 39636746
Ok. I got a little further down the line with a different runtime error (see attached screenshot) on the Set APFs line.
Create-OL-folder-screenshot-erro.jpg
0
 
LVL 39

Expert Comment

by:als315
ID: 39636890
Tocogroup: have you tested my sample?
0
 

Author Comment

by:Tocogroup
ID: 39636906
Hi als315.

Yes I have tested your sample. Hence the screenshot and post above of the second runtime error.
Just to confirm, I checked the libraries as per your screenshot.
0
 
LVL 39

Expert Comment

by:als315
ID: 39636972
Screenshot above is with code from Michael74.
Do you like to add folder to public folders or to personal folders?
0
 

Author Comment

by:Tocogroup
ID: 39637159
Personal folders.
I tried replacing 'Public folders' with 'Personal folders' but had the same runtime error.
0
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
ID: 39637169
I should ask again: have you tested my sample? If there are any errors, can you show them?
0
 

Author Closing Comment

by:Tocogroup
ID: 39637327
Apologies als315. My error !

I've copied your sample into my application and it works absolutely fine.

Many thanks for your patience
Toco
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

774 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