Article ID: 171638
Article Last Modified on 6/6/2005
INFOSTORE.NAME TOPFOLDER.NAME Public Folders IPM_SUBTREE Mailbox - <User Name> Top of Information Store PST Top of Personal FoldersUsing the above table, you know that if you want to find the folder named "Messaging" in the PST, you need to find a TopFolder named "Top of Personal Folders". Then, navigate through these folders until you find the "Messaging" folder.
Option Explicit
Dim objSession As MAPI.Session
Private Sub Form_Load()
Set objSession = CreateObject("MAPI.Session")
objSession.Logon showdialog:=False, newsession:=False
End Sub
Private Sub Command1_Click()
Dim objPSTFolder As Folder
Dim objMessages As Messages
Dim objOneMessage As Message
'Want to find the Messaging folder in my PST. Modify the "Messaging"
'as needed to find the folder you are interested in.
Set objPSTFolder = objFindTargetFolder("Top of Personal Folders", _
"Messaging")
Set objMessages = objPSTFolder.Messages
Set objOneMessage = objMessages.GetFirst
End Sub
Private Function objFindTargetFolder( _
strTargetTopFolder As String, _
strSearchName As String) As Folder
Dim objInfoStores As InfoStores
Dim objInfoStore As InfoStore
Dim objTopFolder As Folder
Dim objPSTFolders As Folders
Dim i As Integer
Set objInfoStores = objSession.InfoStores
'This message box loop is just telling you what the current
'objects are. It is not needed for the function to work
'properly.
For i = 1 To objInfoStores.Count
Set objInfoStore = objInfoStores(i)
Set objTopFolder = objInfoStore.RootFolder
MsgBox "i= " & i & Chr(10) & _
"InfoStore.Name= " & objInfoStores(i).Name & Chr(10) & _
"TopFolder.Name= " & objTopFolder.Name
Next i
'This loop finds the TopFolder you specified.
For i = 1 To objInfoStores.Count
Set objInfoStore = objInfoStores(i)
Set objTopFolder = objInfoStore.RootFolder
If objTopFolder.Name = strTargetTopFolder Then 'Found PST
'Because you can have more than one PST in a profile,
'you may want to put another check here to make sure you have
'the correct PST. This check would need to specify a string
'that is the name of the PST you are looking for.
'It would look something like this:
'If objInfoStore.Name = "MyPST" Then 'Found own PST
' Exit For
'End If
End If
Next i
Set objPSTFolders = objTopFolder.Folders
For i = 1 To objPSTFolders.Count
MsgBox objPSTFolders.Item(i).Name
If objPSTFolders.Item(i).Name = strSearchName Then
Exit For
End If
Next i
Set objFindTargetFolder = objPSTFolders.Item(i)
Set objTopFolder = Nothing
Set objPSTFolders = Nothing
Set objInfoStores = Nothing
Set objInfoStore = Nothing
End Function
Keywords: kbhowto kbmsg KB171638