I Need A (kind of) Dangerous Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a simple way to make a macro that walks through a PST folder
structure and deletes out all of the messages, leaving the folder structure
intact? I need this because I like my file folder structure, but every few
months it grows too large for my thumb drive and I need to start over with an
empty PST. I would copy the current one (it's archived on another machine),
then apply the macro to the copy to start with a fresh PST that has all the
folders the way I like them. I know it's a "dangerous" macro, but I don't
have time to manually clean out the folders and I can't think of a simple way
to do this.
 
Am Thu, 20 Jul 2006 09:19:02 -0700 schrieb Jimboluke:

You could use the follwing template to walk through all the folders. For
starting at the top level you´d call it e.g. with:

LoopFolders Application.Session.Folders, True

Deleting items could be done in LoopItems.

For to copy the structure you could extend the template. I´d probably give
LoopFolders another argument so that there´s one for the source and one for
the target folder.

A folder would be created in LoopFolders by

Set TargetFolder=TargetFolders.Add (SourceFolder.Name)

You´ll find another example for Folders.Add in the VBA help.


Public Sub LoopFolders(Folders As Outlook.Folders, _
ByVal Recursive As Boolean _
)
Dim Folder As Outlook.MAPIFolder

' Loop through all folders.
For Each Folder In Folders
' Loop through folder items
LoopItems Folder.Items

If Recursive Then
' Call this function again for going _
deeper into the object hierarchy.
LoopFolders Folder.Folders, Recursive
End If
Next
End Sub

Private Sub LoopItems(Items As Outlook.Items)
Dim obj As Object

For Each obj In Items
Select Case True
Case TypeOf obj Is Outlook.MailItem
'
Case TypeOf obj Is Outlook.ContactItem
' etc.
End Select
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top