Macro to create folder in PST file

J

Jen

I have leveraged a macro I found online to create a new folder
underneath the default Inbox, with a name entered by the user.

However, what I REALLY want is to create the new folder under a folder
that lives in another PST.

So instead of:

Mailbox
--Inbox
----New Folder
Users PST
--Project

I want it to be created as follows:

Mailbox
--Inbox

Users PST
--Project
----New Folder

Here is the code I have so far - can anyone help?

Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myNewFolder As Outlook.MAPIFolder

Dim newProjectName As String
newProjectName = InputBox(Prompt:="You name please.", _
Title:="ENTER YOUR NAME", Default:="ENTRY")

Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)


Set myNewFolder = myFolder.Folders.Add(newProjectName)
 
D

Dmitry Streblechenko

Instead of using GetDefaultFolder method, use the Namespace.Folders
collection (which represents teh top level folders of all stores in the
profile) to find a folder named "Users PST", the use the MAPIFolder.Folders
collecton to access the subfolders.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
J

Jen

Instead of using GetDefaultFolder method, use the Namespace.Folders
collection (which represents teh top level folders of all stores in the
profile) to find a folder named "Users PST", the use the MAPIFolder.Folders
collecton to access the subfolders.

Would it be at all possible for you to give me an example? I tried
working with this, but just couldn't get anywhere!
 
D

Dmitry Streblechenko

Off the op of my head, no error checking:

set RootFolder = myNamespace.Folders("Users PST")
set myFolder = RootFolder.Folders("Project")
Set myNewFolder = myFolder.Folders.Add(newProjectName)


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
Instead of using GetDefaultFolder method, use the Namespace.Folders
collection (which represents teh top level folders of all stores in the
profile) to find a folder named "Users PST", the use the
MAPIFolder.Folders
collecton to access the subfolders.

Would it be at all possible for you to give me an example? I tried
working with this, but just couldn't get anywhere!
 
J

Jen

Off the op of my head, no error checking:

set RootFolder = myNamespace.Folders("Users PST")
set myFolder = RootFolder.Folders("Project")
 Set myNewFolder = myFolder.Folders.Add(newProjectName)

--
Dmitry Streblechenko (MVP)http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool




Would it be at all possible for you to give me an example?  I tried
working with this, but just couldn't get anywhere!

That worked perfectly - thanks so much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top