0

I would like to store an email that I have just read (so, when I'm closing it) in a folder I select.

I have found and written something like this:

Private Sub myItem_close(Cancel As Boolean)

Dim F As Outlook.MAPIFolder

EventsDisable = True

If TypeOf myItem Is Outlook.mailitem Then

    Set F = myItem.Parent 

    If F = Session.GetDefaultFolder(olFolderInbox) Then 

        Set F = Application.Session.PickFolder

        myItem.Move F

    End If

    EventsDisable = False



End Sub

With this code, when I close an email, I'm asked to select a folder to store it, but code crashes at line myItem.Move F saying that I can't use properties and methods in this event.

Community
  • 1
  • 1
EugeI
  • 1
  • 1
  • Here's a question with an answer which includes VBA code to implement a timer in Outlook: https://stackoverflow.com/questions/12257985/outlook-vba-run-a-code-every-half-an-hour/15207463 You'd need to pass your message id and destination folder to a couple of globals so when the timer fires it can locate the message and its intended destination. – Tim Williams Apr 17 '19 at 23:10

1 Answers1

0

Correct, you cannot move / delete an item while you are in an event raised by that items. Astandard solution is to use a timer - enable it in the event handler, then in the timer event handler, disable the timer and run your code - since you are now out of the original item event handler, there are no limitations.

Unfortunately, there are no timer obj3ects in VBA. Excel exposes Applicationm.OnTime method, but there is nothing like that in the Outlook Object Model unfortunately.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78