Help moving message with VBA

M

Murphybp2

I found the following code, and I would like to modify it. I would
like to change the line that says, "olItem.Delete", so instead of
deleting my message, it will move it to a specified folder. The file
is in a different Outlook data file then my inbox. Does anyone know
how I can do that?



Dim olTask As Outlook.TaskItem
'Using object rather than MailItem, so that it
'can handle posts, meeting requests, etc as well
Dim olItem As Object
Dim olExp As Outlook.Explorer
Dim fldCurrent As Outlook.MAPIFolder
Dim olApp As Outlook.Application


Set olApp = Outlook.CreateObject("Outlook.Application")
Set olTask = olApp.CreateItem(olTaskItem)
Set olExp = olApp.ActiveExplorer
Set fldCurrent = olExp.CurrentFolder


Dim cntSelection As Integer
cntSelection = olExp.Selection.Count


For i = 1 To cntSelection
Set olItem = olExp.Selection.Item(i)
olTask.Attachments.Add olItem
olTask.Subject = "Follow up on " & olItem.Subject
olItem.Delete
Next


olTask.Display
'Set the due date for today
olTask.DueDate = Date
'Set the reminder for 3 hours from now
olTask.ReminderSet = True
olTask.ReminderTime = DateAdd("h", 3, Now)


'Saving the task item, so that in case I close it, I won't lose
'the items which were deleted after being attached to the task
olTask.Save


End Sub
 
M

Michael Bauer [MVP - Outlook]

Am 14 Aug 2006 15:27:34 -0700 schrieb Murphybp2:

Whether you want to move or delete, first turn the loop in a backcount one:

For i = cntSelection To 1 Step -1

Then simply call Move instead of Delete. You need a ref to the target folder
and pass to the Move function. If that´s a subfolder of fldCurrent e.g. then
you could write:

Dim Subfolder as Outlook.Mapifolder
Set Subfolder = fldCurrent.Folders("FolderName")
 

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