Macro to create folder in PST file

  • Thread starter Thread starter Jen
  • Start date Start date
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)
 
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)
 
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!
 
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!
 
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
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
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
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
N Macro in this Project are disabled Outlook VBA and Custom Forms 2
M Outlook 365 Amending code so macro runs within current new mail window Outlook VBA and Custom Forms 0
M Outlook 365 macro - automatically attach file based on subject line Outlook VBA and Custom Forms 0
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 3
H Macro to Delete Duplicate items in Outlook calendar where title is the same and date is the same Outlook VBA and Custom Forms 0
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
mrrobski68 Issue with Find messages in a conversation macro Outlook VBA and Custom Forms 1
G Creating Macro to scrape emails from calendar invite body Outlook VBA and Custom Forms 6
M Use Macro to change account settings Outlook VBA and Custom Forms 0
J Macro to Reply to Emails w/ Template Outlook VBA and Custom Forms 3
C Outlook - Macro to block senders domain - Macro Fix Outlook VBA and Custom Forms 1
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 0
S macro error 4605 Outlook VBA and Custom Forms 0
A Macro Mail Alert Using Outlook 4
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 6
D Outlook 2016 Creating an outlook Macro to select and approve Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
M Outlook 2019 Macro not working Outlook VBA and Custom Forms 0
D Auto Remove [EXTERNAL] from subject - Issue with Macro Using Outlook 21
V Macro to count flagged messages? Using Outlook 2
sophievldn Looking for a macro that moves completed items from subfolders to other subfolder Outlook VBA and Custom Forms 7
S Outlook Macro for [Date][Subject] Using Outlook 1
E Outlook - Macro - send list of Tasks which are not finished Outlook VBA and Custom Forms 3
E Macro to block senders domain Outlook VBA and Custom Forms 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1

Similar threads

Back
Top