Copy, Delete and Purge

P

Pauba

Hello guys:

Could someone please help me out?

I need a macro, bu I do not know even how to begin -- it's for Outlook 2000.

After reading a message in an IMAP folder, I want to move the message to
another folder, nevertheless I want it to desappear (purge it) from the
first folder.
I imagine I need something like:
- copy message to folder xxx
- delete message
- purge message

Thanks,

-N-
 
S

Steve Lang

Hi "Pauba,"

The attached code moves any message that has been read and is not flagged to
another folder. I think you will be able to modify it to fit your needs:

Sub MoveMail()
Dim myNameSpace As NameSpace
Dim myOlApp As Object
Dim myIncomingFolder As MAPIFolder
Dim mySaveFolder As MAPIFolder
Dim myMail As MailItem
Dim myCopy As MailItem

'set the variables
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myIncomingFolder = myFolder.Folders("Inbox")
Set mySaveFolder = myFolder.Folders("Saved Mail")

'move any read mail from Inbox to the saved mail folder
For Each myMail In myIncomingFolder.Items
If myMail.UnRead = False Then
'just move to saved items
If myMail.FlagStatus = olNoFlag Or myMail.FlagStatus = 1 Then
myMail.Move mySaveFolder
End If
End If
Next

'release all the variable space
Set myCopy = Nothing
Set mySaveFolder = Nothing
Set myIncomingFolder = Nothing
Set myNameSpace = Nothing
Set myOlApp = Nothing
End Sub

HTH and have a great day!

Steve Lang
 
P

Pauba

Hello Steve:

Macro stops in this line:

Set myIncomingFolder = myFolder.Folders("Inbox")

It seems it does not recognize "myFolder"

Do you have any idea of what is wrong?

Thanks,

N.
 
S

Steve Lang

Hi "Pauba"

My Bad.

The set statements need to correspond to your environment. If you have a
standard Outlook setup with no custom named folders etc, changing the lines
to this should work... Make sure the names of the folders in the quotes
correspond to the names of the folders in your environment.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myIncomingFolder = myNameSpace.Folders("Inbox")
Set mySaveFolder = myNameSpace.Folders("Saved Mail")

HTH and have a great day!

Steve
 

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

Top