Solved

Outlook 2010 VBA not working to move Email to a different folder

Posted on 2013-01-31
4
762 Views
Last Modified: 2013-01-31
When certain emails arrive, I want to set their category and move them to a specific folder. The following code sets the category successfully, but does not move it to the folder.

(FWIW: The "Alerts" folder is not a subfolder - it is a peer with the InBox)

What am I missing?


Public Sub MoveToFolder(MyEmail As Outlook.MailItem)
    
    Dim MyNamespace As Outlook.NameSpace
    Dim DestFolder As Outlook.MAPIFolder
    
    Set MyOutlook = Outlook.Application
    Set MyNamespace = MyOutlook.GetNamespace("MAPI")

    Set DestFolder = MyNamespace.Folders("Firstname.Lastname@website.com").Folders("Alerts")
    
    MyEmail.Categories = "Problem Report"
    MyEmail.Save
    
    MyEmail.Move (DestFolder)
    MyEmail.Save
        
End Sub

Open in new window

0
Comment
Question by:dossbob
  • 2
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 38841111
The brackets on the destfolder for the move statement are not necessary but I doubt thats it,
put the cursor on the alerts folder in the outlook application explorer then type this in the VBE immediate window (ctrl + G to display):

?application.ActiveExplorer.CurrentFolder.FolderPath

The resultant becomes:

MyNamespace.Folders(PST Name).Folders("Alerts")

Add as many .folders as are necessary to populate all the components in the returned folder address.  ANy problems then get back with the info.

Chris
0
 

Author Comment

by:dossbob
ID: 38841680
1. If the "outlook application explorer" is the window in the bottom left corner, it doesn't have anything at all in it. (Maybe I just don't know how to get it populated)

2. FWIW: Since I don't have an "Alerts" folder in the application explorer, I tried just typing the command you suggested, and got "\\Firstname.Lastname@website.com\Inbox", which is what I would expect.

3. I put a debug message between every line, so I know for sure that all lines execute EXCEPT the last two lines, i.e. the script is failing on the "MyEmail.Move (DestFolder)" line.
0
 

Author Comment

by:dossbob
ID: 38841717
I just re-read your post, and tried removing the parentheses around DestFolder.

Strange as it seems that fixed the problem.

<gripe on>
I've been plagued by punctuation marks since Fortran II on punch cards in 1968. It just seems like compilers would have gotten better in 45 years (:<)
<gripe off>
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 38842538
I am somewhat surprised, I wasn't in a position to try the comment re brackets but would expect the compiler to throw an error hence my thought that it was unlikely.  That said i'm glad it helped.

Chris
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

911 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

23 Experts available now in Live!

Get 1:1 Help Now