How to Move Mail item after processing

Status
Not open for further replies.
Outlook version
Outlook 2007
Email Account
POP3
It has been suggested that all my tasks be included in a VBA script rather than some items in the Outlook rule and others in the script.
I am now trying to do just that.
Put simply I take the Outlook.item (containing words in the Subject) and save the body to a file available for processing on an MT4 (Forex trading) platform.
So I create a file. create a list of any files to be processed and then wish to move the item and that's where I fail.

This code performs the required task but fails with the move.item (I have tried numerous alternatives but I believe this shows what I want to achieve.
Code:
Public fs, f1, f2
Public filepath_part1 As String, filepath_part2 As String, filepath_full As String, myfname As String
Public Sub ChangeSubjectForward(item As Outlook.MailItem)
Dim str1 As String
Dim myline
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
    On Error GoTo Handler
    str1 = item.Body
    str2 = item.Subject
    'If InStr(str1, "Reversal") > 0 And InStr(str2, "Reversals-Signal") > 0 Then
    If InStr(str2, "Reversals-Signal") > 0 Then             '   search the subject
        getmyfile "ADS"                                     '   gets the appropriate file path and name attached to f2
        f2.writeline item.Body
        f2.Close
        writeListofFiles                                    '   writes list of all files in the directory to a file to be accessed from MT4
        ' this is the code that has failed - I'd like to have a folder - say FolderA and sub folder FolderAsignals
        'Set myDestFolder = Inbox.Folders("FolderA")        ' changed for this example
        'item.Move myDestFolder
    End If
    Exit Sub
Handler:
    MsgBox "An unexpected Error has occurred." _
         & vbCrLf & "Error Number: " & Err.Number _
         & vbCrLf & "Error Description: " & Err.Description _
         , vbCritical, "Error!"
    'Resume MsgErr_Exit
End Sub
 
Outlook version
Outlook 2007
Email Account
POP3
What`s the error message saying?
Thanks for the response.

The error occurs when trying to set the 'myDestFolder' and provides the error Object Could Not be Found (see attachment for full details)
I have used the above Folder names as example s but the real folder Exists within INBOX (and is not a sub folder)
 

Attachments

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The "Inbox" variable is not declared, and neither that one nor the "myInbox" variable is set to any folder.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Michael is referring to this - you dim these two:
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder

But you're setting the destination folder but not properly setting the inbox (or myinbox) object
Set myDestFolder = Inbox.Folders("FolderA")

The object and variable names you Dim need to match the names you use in the code.

see Working with VBA and non-default Outlook Folders for how to identify folders

this will work with a subfolder called folder a that is in the inbox:

Dim Ns As Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI")
Set myInbox = Ns.GetDefaultFolder(olFolderinbox)
Set myDestFolder = myInbox.Folders("FolderA")
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
P Move mail item after send Outlook VBA and Custom Forms 2
P when i move inbox mails to another folder in outlook the mail disappears Using Outlook 1
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 5
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 0
M Move new mail to folder based on sender address Outlook VBA and Custom Forms 2
D Help with code to move mail on receipt to another folder based on time received Outlook VBA and Custom Forms 2
S VBA Code to move mail items from search folder to inbox subfolder Outlook VBA and Custom Forms 4
L pin to Outlook move mail Using Outlook 2
T What code to use to move the custom field values to message body when sending e-mail ? Outlook VBA and Custom Forms 8
P move a specified email "From" tag items to a certain folder whenever there is "New Mail" in the inbo Outlook VBA and Custom Forms 5
Douglas Littlefield Macro to move E-mail Outlook VBA and Custom Forms 10
Douglas Littlefield Macro to move mail from inbox to Managed Folder Exchange Server Administration 1
L Macro Move E-mail attachments to a PC Folder Using Outlook 16
N rule to move sent mail to the deleted folder in outlook Using Outlook 4
C Outllok 2010 (14.0.7015.1000 (32bit) converts html mail to rich text when move Using Outlook 1
E Automatically move to other Folder from Inbox when mail comes - MS Outlook Using Outlook 1
L Outlook 2010- Be able to move default Mail folders (Outbox, Draft, etc) Outlook Wishlist 1
J Macro to move mail from Inbox if older than 4 days Using Outlook 4
B MobileMe sync does mail and address book, but, does not move contacts from Outlook to MobileMe Using Outlook 1
C How do I shut down LiveMail & Move what I need to Outlook? I've got conflicts due to setting up Windows Live Mail as temporay until I could get Ou Using Outlook 1
R Mail disappeared when cancelling a drag and drop 'move folder' Using Outlook 1
M I need to move personal folders and address book from outlook express to windows live mail? Using Outlook 1
F Move Windows Live Mail to Outlook 2007 Using Outlook 1
U Move outlook mail with map structure and contacts to Live Mail Using Outlook 3
K Data files open in e-mail attachment form. How do I move these files into the data file location Using Outlook 1
H Automatically move mail to folders by sender... Using Outlook 2
I Everytime i delete or move to another e-mail messsage, outlook shuts down then restarts. After going through this process 3 times it shuts down comple Using Outlook 2
T How to move/change/delete an existing mail contact into a mail user Exchange Server Administration 4
J Can not delete or move e-mail Using Outlook 1
A Messages move to Junk E-mail folder only when I open them Using Outlook 2
B Mailbox move and mail read errors Exchange Server Administration 4
D Help Please !! How to set Outlook 2007 to automaticly move junk mail from my inbox to the junk mail? Using Outlook 3
R How to remove or move the default Junk e-mail folder BCM (Business Contact Manager) 3
P Move emails between 2 mailboxes. Using Outlook 1
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
T Move calendar invites to new calendar Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
Similar threads


















































Top