A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

I Need A (kind of) Dangerous Macro



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 20th 06, 05:19 PM posted to microsoft.public.outlook.program_vba
jimboluke
external usenet poster
 
Posts: 13
Default I Need A (kind of) Dangerous Macro

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.
Ads
  #2  
Old July 21st 06, 05:29 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default I Need A (kind of) Dangerous Macro

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

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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.

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tacking Macro Bob_BLC Outlook and VBA 8 December 5th 07 06:00 AM
Macro PE Outlook - General Queries 2 June 25th 06 09:34 PM
macro trouble windandwaves Outlook and VBA 4 March 21st 06 08:08 PM
$$ looking for someone to write a macro for me [email protected] Outlook and VBA 0 March 15th 06 11:24 PM
Two different kind of spaces Oriolus Outlook Express 13 March 9th 06 11:07 AM


All times are GMT +1. The time now is 05:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.