Macro to move email to inbox subfolder

S

Shay

Hi I need to create a macro to move selected email to an inbox subfolder.

Please forgive me as I am an admin and not a programmer. I found the below
macro on the internet but when I run it I get Runtime error 424 Object
Required.

TIA,
Shay

=======================================
Public Sub mocetosave()
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(6)
Set myitems = myInbox.Items
Set myDestFolder = myInbox.Folders("Saved Mail")
Set myitem = GetCurrentItem()
myitem.MoveTo myDestFolder
End Sub

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application

Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select

Set objApp = Nothing
End Function
 
S

Shay

Hi, thanks for the response. I am sure I am doing something stupid, but when
I run the code I get the error below

Thanks!

===================

Object doesnt support this property or method and highlights "myItem.MoveTo
myDestFolder"

===================
 
E

Eric Legault [MVP - Outlook]

The myInbox object was being instantiated anywhere. Here's the new code,
which I cleaned up a little too because I'm an anal developer:

Public Sub mocetosave()
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(6)
Set myItems = myFolder.Items
Set myDestFolder = myFolder.Folders("Saved Mail")
Set myItem = GetCurrentItem()
myItem.MoveTo myDestFolder
End Sub

Function GetCurrentItem()

'Don't need, Application object is intrinsic and doesn't need to be created
' Dim objApp As Outlook.Application
'
' Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select
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