Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook vba move mail - cant find destination folder 1

Status
Not open for further replies.

longestdrive

Programmer
Jan 23, 2007
26
GB
Hi

I'm dabbling in outlook 2003 vba and I'm struggling with the folders which might be my biggest problem.

I found some basic code to move selected items to a folder and thought I'd try this. However when I run my code I get an error '424 - object required' which I assume means it can't find the folder I'm trying to set as my destination.

Here's the latest version of my code that's causing the error:

Code:
Sub MoveItems()
    Set myOlApp = CreateObject("Outlook.Application")
    Dim Messages As Selection
    Dim Msg As MailItem
    Dim myNamSpace As NameSpace
    Dim Proceed As VbMsgBoxResult
    Dim myFolder As Outlook.MAPIFolder
     
    Set myNamSpace = myOlApp.GetNamespace("MAPI")
    Set Messages = ActiveExplorer.Selection
    'Set myFolder = myNameSpace.Folders("GTD").Folders("Planning")

     
    Debug.Print ("Mess:" & Messages.Count)
    If Messages.Count = 0 Then
        Exit Sub
    End If
    For Each Msg In Messages
        'If Msg.FlagStatus = 2 Then
            Proceed = MsgBox("Are you sure you want to clear the flag and move the message " _
            & """" & Msg & """" & " to the folder " & """" & "Planning" & """" & "?", _
            vbYesNo + vbQuestion, "Confirm Procedure")
            If Proceed = vbYes Then
                Msg.FlagStatus = olNoFlag
                Msg.Move myNamSpace.Folders("GTD").Folders("Planning")
            End If
        'End If
    Next
     
End Sub

Note I've commented out the set myfolder bit on purpose as I thought i'd create the object first but still comes up with the error at the SET statement instead.

For info the 'GTD' folder is at the root of my exchange mailbox, it's not a subfolder of inbox and its not in a personal folder. The folder 'Planning' is a subfolder of 'GTD'

I'm not convinced I have referenced the 'GTD' folder correctly.

Can anyone point me in the right direction please

I've commented out the if statement relating to flag status for now until I fix this problem

Thank you
 
HI,

I have never been able to get this to work , creating a folder on the root of the mailbox (where Inbox) is and move emails to it, It is easy when the folder is within a default location (defaults(inbox, sent items, drafts etc).

however this page seems helpful


Hope this is of use, Rob.[yoda]
 
Thank you.

Using the code on that page I was able to find the folder in the root of the mailbox and get my move message to work. Yay!!!

Thanks for the pointer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top