Subfolder in mail

Dear Team,

I have a process in which i need to check for the year folder in a specific folder.

if exist i need to create a current month folder under that Year folder.

if not exist i need to create year folder then under i need to create a current month subfolder.

iam doing it in outlook

Give a solution for this

Hi @Gokul_Murali

Use this code in invoke code activity.

Dim outlookApp As Object = CreateObject(“Outlook.Application”)
Dim ns As Object = outlookApp.GetNamespace(“MAPI”)
Dim rootFolder As Object = ns.GetDefaultFolder(6) ’ 6 = olFolderInbox, or use olFolderRoot = 1

Dim parentFolder As Object = Nothing
For Each folder As Object In rootFolder.Folders
If folder.Name = baseFolderName Then
parentFolder = folder
Exit For
End If
Next

If parentFolder Is Nothing Then
parentFolder = rootFolder.Folders.Add(baseFolderName)
End If

’ Check or create Year folder
Dim yearFld As Object = Nothing
For Each f As Object In parentFolder.Folders
If f.Name = yearFolder Then
yearFld = f
Exit For
End If
Next
If yearFld Is Nothing Then
yearFld = parentFolder.Folders.Add(yearFolder)
End If

’ Check or create Month folder
Dim monthFld As Object = Nothing
For Each f As Object In yearFld.Folders
If f.Name = monthFolder Then
monthFld = f
Exit For
End If
Next
If monthFld Is Nothing Then
monthFld = yearFld.Folders.Add(monthFolder)
End If

Pass these variables:

Argument Name Value
baseFolderName "Reports" (or any root name)
yearFolder currentYear
monthFolder currentMonth

Thanks!!

Hi @Gokul_Murali

Please refer below post to check if subfolder exists.

Refer below for creating folder if doesn’t exist.

Iam getting an error like this

i have passed argument like below

@sarvesh.b
You have any idea

Hi @Gokul_Murali

Please refer these posts for better understanding

How to check if outlook folder exist - Help / Studio - UiPath Community Forum

Create outlook folders if it does not exist - Help / Studio - UiPath Community Forum

Check below flow.

CheckOutlookFolderExistence.xaml (9.1 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.