Macro to create folder in PST file

Status
Not open for further replies.
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)

-

"Jen" <wordsmithwest@gmail.com> wrote in message

news:772dfae6-3234-4416-8489-1c390927bb90@j4g2000yqe.googlegroups.com...
> 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)
 
J

Jen

On Dec 30, 10:59 pm, "Dmitry Streblechenko" <dmi...@dimastr.com
wrote:
> 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)
> OutlookSpy  - Outlook, CDO
>

> -"Jen" <wordsmithw...@gmail.com> wrote in message

> news:772dfae6-3234-4416-8489-1c390927bb90@j4g2000yqe.googlegroups.com...
>
> >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)


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)

-

"Jen" <wordsmithwest@gmail.com> wrote in message

news:2248c23b-ee19-46a1-93a2-f3d87409067e@e37g2000yqn.googlegroups.com...

On Dec 30, 10:59 pm, "Dmitry Streblechenko" <dmi...@dimastr.com
wrote:
> 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)
>

>

> -"Jen" <wordsmithw...@gmail.com> wrote in message

> news:772dfae6-3234-4416-8489-1c390927bb90@j4g2000yqe.googlegroups.com...
>
> >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)


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

On Dec 31, 8:16 am, "Dmitry Streblechenko" <dmi...@dimastr.com> wrote:
> 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)
> OutlookSpy  - Outlook, CDO
>

> -"Jen" <wordsmithw...@gmail.com> wrote in message

> news:2248c23b-ee19-46a1-93a2-f3d87409067e@e37g2000yqn.googlegroups.com...
> On Dec 30, 10:59 pm, "Dmitry Streblechenko" <dmi...@dimastr.com
> wrote:

>
> > 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)
> >

> >

> > -"Jen" <wordsmithw...@gmail.com> wrote in message

>
> >news:772dfae6-3234-4416-8489-1c390927bb90@j4g2000yqe.googlegroups.com...

>
> > >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)


> 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!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
S Macro to create a new folder with subject line as the folder name Using Outlook 2
M How to Create Macro in Visual Basic to add Contacts from Personal Folder Using Outlook 4
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
A Create Macro for hyperlink(email) in message body Outlook VBA and Custom Forms 9
L Macro Create Contact and Save Using Outlook 2
L Macro Create Contact and Save Using Outlook 8
S Macro to create notification emails Using Outlook 1
N Macro to create task Using Outlook 1
P Please Help me Create a Macro ! Using Outlook 2
S Macro to create a new contact, 2 appointments, and a task Using Outlook 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
R How do I create a macro to put text in certain emails? Outlook VBA and Custom Forms 1
D Create a macro in Outlook to run a rule Outlook VBA and Custom Forms 32
N How Can I create an Outlook Macro to import calendar? Outlook VBA and Custom Forms 1
P How do I create a macro to add contacts from email messages? Outlook VBA and Custom Forms 1
G Macro: Create New Message and Auto populate To Field Outlook VBA and Custom Forms 5
S How to create a macro to insert a signature in Outlook 2007 Outlook VBA and Custom Forms 1
witzker HowTo start a macro with an Button in OL contact form Outlook VBA and Custom Forms 12
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 6
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 23
C Macro to extract sender name & subject line of incoming emails to single txt file Outlook VBA and Custom Forms 3
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
S Macro or plug-in to see if specific person was included in this email Outlook VBA and Custom Forms 4
U Macro for reminders,tasks,calendar Outlook VBA and Custom Forms 4
V macro runs slower on startup than after Outlook VBA and Custom Forms 3
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
G VBA Macro Calendar Printing Assistant 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
R Macro Schedule every day in Outlook Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
Healy Consultants Macro to remove inside organization distribution list email address when reply to all recepients Outlook VBA and Custom Forms 0
geofferyh Cannot get Macro to SAVE more than one message attachment??? Outlook VBA and Custom Forms 5
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
4 Macro to set the category of Deleted Item? Outlook VBA and Custom Forms 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
Dave A Run macro on existing appointment when it changes Outlook VBA and Custom Forms 1
V Outlook Macro to show Flagged messages Outlook VBA and Custom Forms 2
O Run macro automatically at sending an email Using Outlook 11
R Retain Original Message When Forwarding With Macro Outlook VBA and Custom Forms 3
C Macro to add multiple recipients to message Outlook VBA and Custom Forms 3
B Reply and replyall macro is not working Outlook VBA and Custom Forms 1
O Macro - paste as plain text Outlook VBA and Custom Forms 2

Similar threads

Top