Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Access Mail Folders in Outlook

Status
Not open for further replies.

YerMom

Programmer
Oct 3, 2006
127
US
Hi.

I'm running MS Outlook on windows-xp. I need to write a macro that will allow me to some configuration to my outlook folders.

To do this, I want to programmatically get a list of all folders, iterate through the list and do the needed processing to each folder.

How can I get this list? I've tried several times with no success.

Thanks!
 
Gerry,

Thanks for your suggestion. I was in the process of getting together what I've written so far and found a possible solution. when I have more, I'll post it so you and others can see what I did.

Slan
 
I was just working on something similar so here's some code:

Code:
Public Sub Folders()
    
    Dim iFolderCount As Long
    Dim iFolder As Long
    Dim sFolderPath As String
    Dim sFolderName As String
    
    With Application.GetNamespace("MAPI")
        
        iFolderCount = .Folders.Count
        
        For iFolder = iFolderCount To 1 Step -1
            
            sFolderName = .Folders(iFolder).Name
            sFolderPath = .Folders(iFolder).FolderPath
            
            If sFolderName = "RemoveMe" Then
                
                .RemoveStore (.Folders(iFolder))
                
            End If
            
        Next
        
    End With
    
End Sub

If you're not adding or removing folders you can also use 'For Each' like this:

Code:
Dim myNameSpace As NameSpace
Dim myFolder As MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")

For Each myFolder In myNameSpace.Folders

Regards

Nelviticus
 
Hi Nelviticus,

Many thanks!

Regards,
Mum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top