Avatar of bsharath
bsharath
Flag for India asked on

Find Duplicate folders only from 4 of my Pst's. Need to scan each and every folder name in all pst's in the outlook and get the duplicate folder names alone to an excel/txt file.

Hi,

Find Duplicate folders only from 4 of my Pst's. Need to scan each and every folder name in all pst's in the outlook and get the duplicate folder names alone to an excel/txt file.
Scan all sub folders and folders and get the duplicates. Can be 2 or more too. Need the full path shown.

REgards
Sharath
OutlookMicrosoft ApplicationsMicrosoft Office

Avatar of undefined
Last Comment
bsharath

8/22/2022 - Mon
Dave

Sharath,
Change these lines to your  PST file names
  • MyPsts(1) = "2003"
  • MyPsts(2) = "2004"
  • MyPsts(3) = "2005"
  • MyPsts(4) = "2006"
The code will dump any dupes (against the original name) to c:\duplist.csv
Cheers
Dave

ption Explicit
 
Sub FolderList()
    Dim myNamespace As Outlook.NameSpace
    Dim MyPsts(1 To 4) As String, Pst
    Dim MyDic, objFSO, objTextFile
    Dim MainFolder As MAPIFolder
 
    Set objFSO = CreateObject("scripting.filesystemobject")
    Set objTextFile = objFSO.createtextfile("c:\duplist.csv")
    Set myNamespace = Application.GetNamespace("MAPI")
    Set MyDic = CreateObject("scripting.dictionary")
    MyPsts(1) = "2003"
    MyPsts(2) = "2004"
MyPsts(3) = "2005"
MyPsts(4) = "2006"
    For Each Pst In MyPsts
        Set MainFolder = myNamespace.Folders(Pst)
        Call ProcessFolder(MainFolder, MyDic, objTextFile)
    Next
    Set MyDic = Nothing
    objTextFile.Close
    Set objFSO = Nothing
    
    MsgBox "Done"
End Sub
 
 
 
Sub ProcessFolder(ByVal MainFolder As MAPIFolder, ByVal MyDic, ByVal objTextFile)
    Dim objFolder As Outlook.MAPIFolder
 
    For Each objFolder In MainFolder.Folders
        If MyDic.exists(objFolder.Name) Then
            objTextFile.Write objFolder.FolderPath & "," & Right$(MyDic(objFolder.Name), Len(MyDic(objFolder.Name)) - InStr(MyDic(objFolder.Name), "|||") - 2)
            objTextFile.Writeline
        Else
            MyDic.Add objFolder.Name, objFolder.Name & "|||" & objFolder.FolderPath
        End If
        Call ProcessFolder(objFolder, MyDic, objTextFile)
    Next
    Set objFolder = Nothing
End Sub

Open in new window

bsharath

ASKER
Thanks Dave i get this

the operation failed. An object could not be found...

        Set MainFolder = myNamespace.Folders(Pst)
I have changed the code with 4 pst file names
Dave

Sharath,
The codde below will run over all all of your folders - lets see if this works for you before we refine it to your 4 specific psts
Cheers
Dave

Option Explicit
Sub FolderList()
    Dim myNameSpace As Outlook.NameSpace
    Dim Pst
    Dim MyDic, objFSO, objTextFile
    Dim MainFolder As MAPIFolder
 
    Set objFSO = CreateObject("scripting.filesystemobject")
    Set objTextFile = objFSO.createtextfile("c:\duplist.csv")
    Set myNameSpace = Application.GetNamespace("MAPI")
    Set MyDic = CreateObject("scripting.dictionary")
 
    For Each Pst In myNameSpace.Folders
        Set MainFolder = myNameSpace.Folders(Pst.Name)
        Call ProcessFolder(MainFolder, MyDic, objTextFile)
    Next
    Set MyDic = Nothing
    objTextFile.Close
    Set objFSO = Nothing
 
    MsgBox "Done"
End Sub
 
 
 
Sub ProcessFolder(ByVal MainFolder As MAPIFolder, ByVal MyDic, ByVal objTextFile)
    Dim objFolder As Outlook.MAPIFolder
 
    For Each objFolder In MainFolder.Folders
        If MyDic.exists(objFolder.Name) Then
            objTextFile.Write objFolder.FolderPath & "," & Right$(MyDic(objFolder.Name), Len(MyDic(objFolder.Name)) - InStr(MyDic(objFolder.Name), "|||") - 2)
            objTextFile.Writeline
        Else
            MyDic.Add objFolder.Name, objFolder.Name & "|||" & objFolder.FolderPath
        End If
        Call ProcessFolder(objFolder, MyDic, objTextFile)
    Next
    Set objFolder = Nothing
End Sub

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
bsharath

ASKER
Dave can we exclude the Public folders please... As it has already taken an hr to read the public folders alone...
bsharath

ASKER
Dave can we exclude the Public folders please... As it has already taken an hr to read the public folders alone...
ASKER CERTIFIED SOLUTION
Dave

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bsharath

ASKER
Thanks...
Results would be if duplicate it will be seen in Colum C & D and so on?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bsharath

ASKER
Thanks...
Results would be if duplicate it will be seen in Colum C & D and so on?
Dave

Column A will contain the orginal location
Column B the duplicate path
If there were say three repeat foldernames you would get
A                          B
orig path          dup path1
x xxxx                   yyyy
orig path          dup path2
Cheers
Dave
 
 
bsharath

ASKER
Thanks a lot Dave...
Any help on the other post...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
bsharath

ASKER
Thanks a lot Dave...
Any help on the other post...