Macro to move email to backup pst folder

A

Adam

Hi All,

I want to create a macro that moves the selected email(s) to my archive.pst
folder called 'Inbox'.

I can see various blogs that have a macro however this only moves it within
your Inbox, not amongst other pst folders you have open in Outlook?

The exchange we have at work is held together with elastic bands so
filespace is a premium so I had to create a local back pst file for my
archive needs.

If anyone knows of a macro that could help me achieve this it would be
fantastic!

Kind regards,

Adam
 
D

Danny J. Lesandrini

Adam:

I suspect there are Access developers who know enough about the Outlook
automation model to help you with this, but unless it's something one of us
has done in VBA, we aren't likely to have the code sample lying around.

Maybe the Outlook newsgroups would result in a quicker solution.

That having been said, here's a couple of thoughts:

1) Why a macro? and perhaps ... It can't be done in a macro.

2) VBA Automation code below isn't perfect, but does work.


Public Function OutlookFoo() As Long
On Error GoTo Err_Handler

Dim appOutlook As Outlook.Application
Dim objInbox As Outlook.MAPIFolder
Dim objMapiFldr As Outlook.MAPIFolder
Dim objInboxItems As Outlook.Items
Dim objOutMail As Outlook.MailItem ' As Object

Const cSentMail As Long = 5
Const cInbox As Long = 6

Set appOutlook = CreateObject("Outlook.Application")

Set objInbox = appOutlook.GetNamespace("Mapi").GetDefaultFolder(cInbox)
Set objMapiFldr = objInbox.Folders("Test")

Set objInboxItems = objInbox.Items
For Each objOutMail In objInboxItems
objOutMail.Move objMapiFldr
Next

Exit_Here:
Set objOutMail = Nothing
Set objInbox = Nothing
Set appOutlook = Nothing
Set objInboxItems = Nothing
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Next
End Function
 

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