Forum

Add Create Outlook ...
 
Notifications
Clear all

Add Create Outlook Folder to existing Macro that Creates Windows folder

4 Posts
2 Users
0 Reactions
268 Views
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

I have a functional VBA script I found online.  However I would like to add one more task to this macro, but I have never done anything like this.  When a folder is created via this macro, I would like it to also create a folder of the same name within Outlook.  The folder would be in a subfolder within my archive folder called "Projects".  So for example, in Outlook based on how this sheet is completed there would be 2 folders created.

Archive > Projects > 34 - Template in Word

Archive > Projects > 38 - Training Manual

The above format is only to show the path of the new folders.  The existing portion to create the Windows folders works perfectly.

* Please note, I looked for special code tags for my VBA script that I am sharing, but did not see them anywhere.

 

Option Explicit
Sub MakeFolders()

Dim Folder As Range
Dim FolderPath As String

FolderPath = Range("MakeFolderPath").Value

On Error Resume Next

For Each Folder In Range("MakeFolderNames[Folder Name]")
MkDir FolderPath & "" & Folder.Text
Next Folder

End Sub

 
Posted : 10/12/2021 12:12 pm
(@debaser)
Posts: 836
Member Moderator
 

You'll need something like this:

Option Explicit
Sub MakeFolders()

Dim Folder As Range
Dim FolderPath As String

FolderPath = Range("MakeFolderPath").Value

Dim OutlookApp As Object
Set OutlookApp = GetObject(, "Outlook.Application")
Dim ProjectsFolder As Object
Set ProjectsFolder = OutlookApp.GetNamespace("MAPI").Folders("your email address here").Folders("Archive").Folders("Projects")

On Error Resume Next

For Each Folder In Range("MakeFolderNames[Folder Name]")
MkDir FolderPath & "" & Folder.Text

ProjectsFolder.Folders.Add Folder.Text
Next Folder

End Sub

 
Posted : 14/12/2021 7:13 am
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

@Velouria,

 

That worked perfectly!!!!  I can't tell you how many times I have had a need to create a Windows and corresponding Outlook Project folder.  I will get a ton of use from that code.  Thanks so very much!

 
Posted : 14/12/2021 12:09 pm
(@debaser)
Posts: 836
Member Moderator
 

You're welcome. 🙂

 
Posted : 15/12/2021 11:03 am
Share: