• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

How do I create a new Outlook folder from Excel ?

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
Tocogroup
Asked:
Tocogroup
  • 6
  • 4
1 Solution
 
Michael FowlerSolutions ConsultantCommented:
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
 
TocogroupAuthor Commented:
I'm getting a 'User-defined type' error at run-time. Please see attached screenshot.
0
 
TocogroupAuthor Commented:
Let's try uploading the file this time
Create-OL-folder-screenshot.jpg
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
als315Commented:
Look at sample
You will need some libraries in your project (Tools-References in VBA Editor):
referencesAddFolder.xlsm
0
 
TocogroupAuthor Commented:
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
 
als315Commented:
Tocogroup: have you tested my sample?
0
 
TocogroupAuthor Commented:
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
 
als315Commented:
Screenshot above is with code from Michael74.
Do you like to add folder to public folders or to personal folders?
0
 
TocogroupAuthor Commented:
Personal folders.
I tried replacing 'Public folders' with 'Personal folders' but had the same runtime error.
0
 
als315Commented:
I should ask again: have you tested my sample? If there are any errors, can you show them?
0
 
TocogroupAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now