Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2016, 02:36 AM
gmayor's Avatar
gmayor gmayor is offline Saving group of individual e-mails Windows 10 Saving group of individual e-mails Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can certainly process all the folders under your default inbox, which I think is what you are asking. It needs a further macro to process the folders (which becomes the main macro) and some modifications to the ProcessFolder macro (see below) to take the input from the new macro (the other functions are still required).

You will notice I have added some commented out lines in the ProcessFolder sub. If restored, these lines add a category to each processed message, so that next time the process is run, the process checks for the added category and if present, the categorised messages will not be processed again.




Code:
Option Explicit

Sub SaveMessages()
'Graham Mayor - http://www.gmayor.com
Dim cFolders As Collection
Dim olFolder As Outlook.Folder
Dim subFolder As Outlook.Folder
Dim olNS As Outlook.NameSpace
Dim strPath As String
Dim sSubPath As String
Dim sStore As String

    strPath = InputBox("Enter the path to save the messages." & vbCr & _
                       "The path will be created if it doesn't exist.", _
                       "Save Message", "C:\Outlook Message Backup\")

    Do Until Right(strPath, 1) = Chr(92)
        strPath = strPath & Chr(92)
    Loop

    Set cFolders = New Collection
    Set olNS = GetNamespace("MAPI")
    cFolders.Add olNS.GetDefaultFolder(olFolderInbox)
    Do While cFolders.Count > 0
        Set olFolder = cFolders(1)
        cFolders.Remove 1
        sStore = olFolder.Store
        sSubPath = Replace(olFolder.FolderPath, "\\" & sStore & "\", strPath)
        CreateFolders sSubPath
        ProcessFolder olFolder, sSubPath
        If olFolder.folders.Count > 0 Then
            For Each subFolder In olFolder.folders
                cFolders.Add subFolder
            Next subFolder
        End If
    Loop
lbl_Exit:
    Set olFolder = Nothing
    Set subFolder = Nothing
    Exit Sub
End Sub

Private Sub ProcessFolder(olMailFolder As Outlook.Folder, sPath As String)
'Graham Mayor - http://www.gmayor.com
Dim olItems As Outlook.Items
Dim olMailItem As Outlook.MailItem
Dim i As Long
Dim ofrm As New frmProgress
Dim PortionDone As Double

    On Error GoTo err_Handler

    Set olItems = olMailFolder.Items
    ofrm.Show vbModeless
    i = 0
    For Each olMailItem In olItems
        i = i + 1
        'If Not olMailItem.categories = "Backed-up To File" Then
            PortionDone = i / olItems.Count
            ofrm.Caption = olMailFolder.Name & " - Processing " & i & " of " & olItems.Count
            ofrm.lblProgress.Width = ofrm.fmeProgress.Width * PortionDone
            SaveMessage olMailItem, sPath
            'olMailItem.categories = "Backed-up To File"
            'olMailItem.Save
            DoEvents
        'End If
    Next olMailItem
    Unload ofrm
lbl_Exit:
    Set ofrm = Nothing
    Set olItems = Nothing
    Set olMailItem = Nothing
    Exit Sub
err_Handler:
    MsgBox Err.Number & vbCr & Err.Description
    Err.Clear
    GoTo lbl_Exit
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 06-12-2016, 11:22 AM
gerryex gerryex is offline Saving group of individual e-mails Windows 10 Saving group of individual e-mails Office 2016
Novice
Saving group of individual e-mails
 
Join Date: Dec 2015
Location: Florida
Posts: 14
gerryex is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You can certainly process all the folders under your default inbox, which I think is what you are asking. It needs a further macro to
. . . . .
Hi gmayor,

WOW! Thanks that's exactly what I want to do. I'm going out soon so I can't try it today, but I saved your new VBA code and will give it a try soon and let you know how it turns out. I assume I should just delete the current macro and then import the new code which will create the new overall macro along with the revised one.

THANKS AGAIN!
Gerry
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving group of individual e-mails Saving Mails as PDF Michel777 Outlook 2 01-11-2015 07:54 AM
Saving sent mails to specific folder kammil121 Outlook 0 10-22-2014 02:26 AM
Saving a contact group received from someone else kcmihrguy Outlook 0 08-20-2014 06:20 AM
Saving senders email to contact group RicWCO Outlook 0 03-26-2012 10:03 PM
Saving group of individual e-mails group incoming e-mails into 2 search folders taher Outlook 1 11-07-2011 11:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft