[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB Outlook move emails

Posted on 2007-08-08
3
Medium Priority
?
1,220 Views
Last Modified: 2008-01-09
Can anyone help with my code below to get it to remove and save the attachment then move the Email.
Code saves attachment fine but for some reason the email do not get moved -

        Dim oApp As Outlook.Application
        Dim oFolder As Outlook.MAPIFolder

        Dim oFolder3 As Outlook.MAPIFolder
        Dim oNS As Outlook.NameSpace
        Dim oMsg As Object
        Dim oAttachments As Outlook.Attachment
        Dim strControl
        Dim i As Integer
        Dim filename As String
        oApp = New Outlook.Application
        oNS = oApp.GetNamespace("MAPI")


        oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        oFolder = oFolder.Folders.Item("fax_test")

        oFolder3 = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        oFolder3 = oFolder3.Folders.Item("THE_BRC")


        strControl = 0

        For Each oMsg In oFolder.Items ' Loop through Folder Items

            For Each oAttachments In oMsg.Attachments
                filename = "H:\ocrff\import\fax.fof\" & oAttachments.FileName
                oAttachments.SaveAsFile(filename)
             
            Next oAttachments

           oMsg.MOVE(oFolder3)

        Next oMsg
0
Comment
Question by:ipavlo
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 19656131
Try this:

        Dim oApp As Outlook.Application
        Dim oFolder As Outlook.MAPIFolder

        Dim oFolder3 As Outlook.MAPIFolder
        Dim oNS As Outlook.NameSpace
        Dim oMsg As Object
        Dim oAttachments As Outlook.Attachment
        Dim strControl
        Dim i As Integer
        Dim filename As String
        Set oApp = New Outlook.Application
        Set oNS = oApp.GetNamespace("MAPI")

        Set oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        Set oFolder = oFolder.Folders.Item("fax_test")

        Set oFolder3 = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        Set oFolder3 = oFolder3.Folders.Item("THE_BRC")

        strControl = 0

        For i = oFolder.Items.Count To 1 Step -1
            Set oMsg = oFolder.Items.Item(i)

            For Each oAttachments In oMsg.Attachments
                filename = "H:\ocrff\import\fax.fof\" & oAttachments.FileName
                oAttachments.SaveAsFile(filename)
             
            Next oAttachments

           oMsg.MOVE oFolder3

        Next
0
 

Author Comment

by:ipavlo
ID: 19657190
Thank you very much :-)
0
 
LVL 76

Expert Comment

by:David Lee
ID: 19657985
You're welcome!
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question