vba Script to help with some PST searching?

  • Thread starter Thread starter Troy Bruder
  • Start date Start date
T

Troy Bruder

I'm looking for some way to script a search for approximately 35 keywords
within a PST file... I would like for the script to create a subfolder for
each key word, then place a COPY of any message found within the PST into
the associated subfolder..

Anyone ever do anything like this before?? I would be eternally grateful!!


Troy
 
Hi,

here is a sample for iterating through the folders with CDO 1.21
(optional installation). You need to logon a MAPI Session. The object
hierarchy for the first method´s
argument "oFolders" is: Session.InfoStores(i).RootFolder.Folders.

In the last method you can search in each item for your keywords. For
the CDO properties please visit www.cdolive.com/cdo10.htm.

(You could use the OOM instead of CDO, of course, whích is easier to
handle - and very slowly...)


'-----------------------------------------------------------------------
-----
' Procedure:LoopInfoStoreFolders
' DateTime :04.03.2005 07:18
' Author :Michael Bauer
' Purpose :Loop through the Mapi folders hierarchy of one InfoStore
' for handling each folder item
'-----------------------------------------------------------------------
-----
Public Sub LoopInfoStoreFolders(oFolders As MAPI.Folders, _
ByVal bRecursive As Boolean _
)
Dim oFld As MAPI.Folder

' Loop through all folders.
For Each oFld In oFolders
' Loop through folder items
LoopItems oFld.Messages

If bRecursive Then
' Call this function again for going _
deeper into the object hierarchy.
LoopInfoStoreFolders oFld.Folders, bRecursive
End If
Next
End Sub

Private Sub LoopItems(oItems As MAPI.Messages)
Dim obj As Object

For Each obj In oItems
Select Case True
Case TypeOf obj Is MAPI.Message
HandleMessage obj
Case TypeOf obj Is MAPI.AppointmentItem
' Another method for handling AppointmentItems
' etc.
End Select
Next
End Sub

Private Sub HandleMessage(oItem As MAPI.Message)
' Do s.th. with the object.
End Sub
 
So would I start Outlook and open this PST, then run this script from
the command prompt with CScript or something? (Sorry, I'm not sure how
to run vba scripts)...


Also, can you add a line or two that shows how to COPY a message meeting
the search keyword into a folder of the same name as the keyword??

Thank you VERY much.

Troy
 
Please add this sample to ThisOutlookSession:

Public Sub StartSample()
' Loops through the first InfoStore
LoopInfoStoreFolders LogOn.InfoStores(1).RootFolder.Folders, False
End Sub

Private Function LogOn() As MAPI.Session
Dim oSess As MAPI.Session
Set oSess = CreateObject("MAPI.Session")
oSess.LogOn , , False, False, , True
Set LogOn = oSess
End Function

An easy method for starting the script is: right click on the menubar,
select "Customize", "Commands", "Macros" in the left pane and
"StartSample" in the right one.
Also, can you add a line or two that shows how to COPY a message meeting
the search keyword into a folder of the same name as the keyword??

No, a) there are more than two lines necessary, b) I´m sure you want to
do a little bit by yourself, won´t you?

It´s really easy: Please go to the VBA help and search for "Copy" and
(MapiFolders) "Add". There a samples available. For comparing your
keywords with anything you want to you can use =, like and/or the Instr
function (also explained in the help).
 
Thank you for this much.. I'm "under-the-gun" restoring/searching
mailboxes for a lawsuit.. I just don't have to the time to research the
way to actually run this.. I'm clueless with vba..

Thanks again.
Troy
 
Maybe you´ve selected the wrong NG. This one is for helping people who
want to code/learning VBA. You could search for a developer who´s doing
the job for you instead.
 
Back
Top