View Full Version : Create folder an subfolder
sastoka
04-12-2017, 02:06 AM
Hi there,
I would like to know if there is a way to create folder with subfolder.
I would like to have an input box for the name of the folder. If not possible just a harcoded name such as "Employee name"
the sub folder are all the same
Contract Documents
Personnal Documents
Remuneration
Visa/Trip
Insurance
And again if possible a choose folder box for the parent folder. If not possible straight into the inbox is fine.
I'm using outlook 2013.
Many thanks to all.
Best regards,
Sastoka
gmayor
04-12-2017, 03:52 AM
The following will allow you to choose the target folder and name the sub folder
Option Explicit
Sub CreateSubFolder()
Dim olNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim strName As String
On Error Resume Next
Set olNS = GetNamespace("MAPI")
Set olFolder = olNS.PickFolder
strName = InputBox("Enter sub-folder name")
If strName = "" Then
MsgBox "No name entered!"
GoTo lbl_Exit
End If
olFolder.folders.Add strName
lbl_Exit:
Set olNS = Nothing
Set olFolder = Nothing
Exit Sub
End Sub
sastoka
04-12-2017, 07:19 AM
Hi,
Thanks a lot.
That not complete but with the start you gave I did this.
Option Explicit
Sub CreateSubFolder()
Dim olNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim strName As String
Dim Folders As Outlook.Folders
On Error Resume Next
Set olNS = GetNamespace("MAPI")
Set olFolder = olNS.PickFolder
strName = InputBox("Enter sub-folder name")
If strName = "" Then
MsgBox "No name entered!"
GoTo lbl_Exit
End If
olFolder.Folders.Add strName
Set Folders = olFolder.Folders.Item(strName).Folders
Folders.Add "Doc Contrat", olFolderInbox
Folders.Add "Doc Personel", olFolderInbox
Folders.Add "Remuneration", olFolderInbox
Folders.Add "Visa/Trip", olFolderInbox
Folders.Add "Assurance", olFolderInbox
lbl_Exit:
Set olNS = Nothing
Set olFolder = Nothing
Exit Sub
End Sub
And this does everything I want.
Many thanks.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.