Solved

Moving a mail message from inbox to a custom folder

Posted on 1998-12-02
4
146 Views
Last Modified: 2010-08-05
I am writting a VB program that loops thru all the emails in Outlook 97's "Inbox" folder and then moves some to a special folder that I created called "Processed UnitedWay Pledges." I cannot move the emails from the inbox to my special folder. Does anyone know how I might accomplish this task? Everything else is working fine.
Thanks!
0
Comment
Question by:beaumont
  • 2
  • 2
4 Comments
 

Author Comment

by:beaumont
ID: 1447887
Edited text of question
0
 

Author Comment

by:beaumont
ID: 1447888
Edited text of question
0
 
LVL 2

Accepted Solution

by:
cedricd earned 50 total points
ID: 1447889
*** Login Function Outlook_LOGIN() As Boolean    On Error GoTo Outlook_Login_Err
        Set theApp = CreateObject("Outlook.Application")
    Set theNameSpace = theApp.GetNamespace("MAPI")    MAILBOX_STATE = 200    
    Exit FunctionOutlook_Login_Err:    Login_Outlook = False    Exit Function
End FunctionFunction Outlook_SaveAttachment(Location As String)
    On Error GoTo Outlook_SaveAttachment_Err    
    Set myAttachments = InboxFolder.Items(EachItem).Attachments
    myAttachments.Item(EachItem).SaveAsFile Location & "\" & myAttachments.Item(EachItem).DisplayName
    Exit Function'*** Check for mail  
Nout = Locate_Mail(Inbox, "", "Registration_", "")        
Function Locate_Mail(Folder$, From$, Subject$, Body$) As Boolean
    On Error GoTo Locate_Mail_Err        
    Set InboxFolder = theNameSpace.GetDefaultFolder(Folder$)          
    For Each MailItem In InboxFolder.Items
        If InStr(1, MailItem.Subject, Subject$, vbTextCompare) Then
            EachItem = EachItem + 1            x = (InboxFolder.Items.Count)
            'Form1.List1.AddItem "SenderName :" & InboxFolder.Items(EachItem).SenderName
            'Form1.List1.AddItem "ReceivedTime :" & InboxFolder.Items(EachItem).ReceivedTime
            'Form1.List1.AddItem "SentOn :" & InboxFolder.Items(EachItem).SentOn
            'Form1.List1.AddItem "To:" & InboxFolder.Items(EachItem).To
            'Form1.List1.AddItem "Subject : " & InboxFolder.Items(EachItem).Subject
            'Form1.List1.AddItem "UnRead : " & InboxFolder.Items(EachItem).UnRead
            'Form1.List1.AddItem "UnRead : " & InboxFolder.Items(EachItem).Attachment
            'Set myAttachments = InboxFolder.Items(EachItem).Attachments
            'myAttachments.Item(1).SaveAsFile "C:\My Documents\" & myAttachments.Item(1).DisplayName
        End If            Next            If EachItem = 0 Then
        '*** If no mail item found then continue looking
        MAILBOX_STATE = 200        Exit Function    Else
        '*** If mail found set state        MAILBOX_STATE = 250        
    End If            Exit FunctionLocate_Mail_Err:Locate_Mail = False
Exit FunctionEnd Function        Function Outlook_SendMail(Letter As String)
    On Error GoTo Outlook_SendMail_Err    Dim Msg As String    Dim theMailItem
        Select Case Letter        Case "Auto_OneTel"            Msg = "Andrew, "
    Msg = Msg & Chr$(13) & "Confirming receipt of " & InboxFolder.Items(1).Attachments.Item(1).DisplayName
    Msg = Msg & "  received on " & Outlook_Get_Weekday & " " & InboxFolder.Items(EachItem).ReceivedTime & Chr$(13)
    Msg = Msg & "Kind Regards," & Chr$(13)
    Msg = Msg & "OneTel.Services@GlobalOne.net" & Chr$(13)
    Msg = Msg & "<< This is a system generated message >>"    Debug.Print Msg
        Set theMailItem = theApp.CreateItem(olMailItem)    With theMailItem
        .Subject = "Confirmation File- " & InboxFolder.Items(EachItem).Attachments.Item(1).DisplayName
        .Body = Msg        .Recipients.Add "malcolm.wilson@globalone.net"
        .Recipients.Add "wirereg@one.net.au"
        .Recipients.Add "kevinr@one.net.au"        .Send    End With    DoEvents
    Exit Function'*** Move mail to folder
Function MoveMail_To_Folder(Folder As String)
Set mydestfolder = InboxFolder.Folders(Folder)
Set myItem = InboxFolder.Items(EachItem)myItem.Move mydestfolderEnd Function
0
 
LVL 2

Expert Comment

by:cedricd
ID: 1447890
Sorry for the presentation of my reply but i had a little problem
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now