+ Reply to Thread
Results 1 to 5 of 5

VBA to move email from inbox to subfolder

Hybrid View

Marijke VBA to move email from inbox... 03-02-2017, 10:21 AM
cytop Re: VBA to move email from... 03-02-2017, 10:26 AM
Marijke Re: VBA to move email from... 03-02-2017, 11:43 AM
skatonni Re: VBA to move email from... 03-17-2017, 05:53 PM
Marijke Re: VBA to move email from... 04-11-2017, 02:31 AM
  1. #1
    Forum Contributor
    Join Date
    12-18-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 365
    Posts
    108

    VBA to move email from inbox to subfolder

    Hi,

    I have a very basic code that helps me move selected emails from the Inbox to a subfolder, but it will not move it.
    My VBA keeps telling me the folder (ToDo) does not exist, but that is likely because it is a subfolder, and it is not directly listed underneath the mailbox.

    The structure of the mailbox is setup like this:
    - Mailbox - Marijke
    - Inbox
    --> subfolder of inbox: Today
    --> subfolder of Today: ToDo

    This is part of the code I have where the mailfolder is selected:

    'Define path to the target folder
    Set moveToFolder = ns.Folders("Mailbox - Marijke").Folders("ToDo")
    Can anyone help me obtain the code I need to move my emails?

    Thank you!

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to move email from inbox to subfolder

    It would be more effective to define an Outlook rule to move emails as they are received, if you can identify which messages are to be moved.

    You haven't included the code which determines which to move, so this is a comment only.

  3. #3
    Forum Contributor
    Join Date
    12-18-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 365
    Posts
    108

    Re: VBA to move email from inbox to subfolder

    I have considered doing this, but we have so many emails coming in that need grooming that we have reached the maximum number of rules.

    The macro itself works.
    if I put a different folder in (for example 'Sent') it moves the email. it's just with the way the subfolder is positioned that seems to be my challenge.

    This is the complete code I have:

    'Outlook VB Macro to move selected mail item(s) to a target folder
    Sub MoveSelectedEmailToDeistalls()
    On Error Resume Next
    
    Dim ns As Outlook.NameSpace
    Dim moveToFolder As Outlook.MAPIFolder
    Dim objItem As Outlook.MailItem
    Dim MyItem As Object
    
    Set ns = Application.GetNamespace("MAPI")
    Set MyItem = ActiveExplorer.Selection(1)
        
    ' mark selected email as READ
            MyItem.UnRead = False
            
    'Define path to the target folder
    Set moveToFolder = ns.Folders("marijkemail@mailbox.com").Folders("ToDo")
    
    If Application.ActiveExplorer.Selection.Count = 0 Then
       MsgBox ("No item selected")
       Exit Sub
    End If
    
    
    If moveToFolder Is Nothing Then
       MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
    End If
    
    For Each objItem In Application.ActiveExplorer.Selection
       If moveToFolder.DefaultItemType = olMailItem Then
          If objItem.Class = olMail Then
             objItem.Move moveToFolder
          End If
      End If
    Next
    
    Set objItem = Nothing
    Set moveToFolder = Nothing
    Set ns = Nothing
    Set MyItem = Nothing
    
    
    End Sub

  4. #4
    Forum Contributor
    Join Date
    08-27-2006
    Posts
    136

    Re: VBA to move email from inbox to subfolder

    Walk the chain of folders, the same as opening folders manually.

    Set moveToFolder = ns.Folders("marijkemail@mailbox.com").Folders("Inbox").Folders("Today").Folders("ToDo")
    To mark "Solved" go to Thread Tools.

  5. #5
    Forum Contributor
    Join Date
    12-18-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 365
    Posts
    108

    Re: VBA to move email from inbox to subfolder

    Thank you skatonni, your solution worked perfectly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 14
    Last Post: 09-18-2016, 08:13 AM
  2. Replies: 0
    Last Post: 09-18-2015, 03:20 AM
  3. VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolder
    By Marijke in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2014, 12:14 PM
  4. Move categorized email from Inbox to a subfolder named exactly as the category
    By lennasaurus in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 11-20-2013, 03:24 AM
  5. [SOLVED] Mkdir command button to add subfolder/subfolder
    By frefry4 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-17-2013, 06:28 PM
  6. Moving an e-mail from a subfolder in Mailbox to the equivalent subfolder in an archive PST
    By johncassell in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2012, 11:31 AM
  7. Move Inbox Subfolder Items by Category to Folder
    By ker9 in forum Outlook Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2011, 02:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1