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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Outlook problem

Status
Not open for further replies.

RaceAap

IS-IT--Management
Sep 5, 2001
39
NL
Code:
Sub Test()
    Dim oApp
    Dim oNS
    Dim oMsg
                    
    Set oApp = New Outlook.Application
    Set oNS = oApp.GetNamespace("MAPI")
    Set oFolder = oApp.ActiveExplorer.CurrentFolder
    Set myDestFolder = oFolder.Folders("Test")
   
    Set oFolder = oApp.ActiveExplorer.CurrentFolder

    For Each oMsg In oFolder.Items
        With oMsg
           oMsg.Move myDestFolder
        End With
    Next

End Sub


This code should move all messages from my inbox to a sub folder of my indox named 'Test'... But it only moves 3 or 2 at a time...

Does anyone know why it doesn't work ??



Thanx,

Lon
 
Try changing your code a bit to this:

Code:
dim oMsg as MailItem
' the other declarations
'**********************'
For Each oMsg In oFolder.Items
    oMsg.Move myDestFolder
Next

I hope this helps!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
I than get the error that type's do not match on:

For Each oMsg In oFolder.Items

When I only do a dim oMsg, it works but does only 2 or 3 at a time.. :(

Is there an other way of moving the messages?


When I use the same kind of code but add a part to save all attachments to a folder on my pc, it does handle all the messages..... very wierd that it doesn't move them


Thanx,

Lon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top