+ Reply to Thread
Results 1 to 4 of 4

Thread: Best way to copy all emails without opening each one

  1. #1
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    537

    Best way to copy all emails without opening each one

    I know absolutely nothing about using Outlook....is there a way to copy the contents of all email folders to a thumb drive?

    A lady here at work tried to just copy the folders by selecting and copying, but the contents did not come with it in a format that can be read. There are hundreds of emails on a former employee's computer(he was fired this past Monday) here at work that we need to save.



    EDIT: Domski's code worked great!
    Last edited by jwright650; 03-31-2011 at 08:55 AM.
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  2. #2
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: Best way to copy all emails without opening each one

    I was going to adapt some code I'd written but this seems to do the job far better:

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=875

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: Best way to copy all emails without opening each one

    Thought would post my effort anyway, borrowing DRJ's function for stripping out the illegal characters:

    Sub Save_All_Mail()
        
        Dim itm As Object
        Dim mFldr As Outlook.MAPIFolder
        Dim mlItm As Outlook.MailItem
        Dim strFileName As String
    
    '    Set mFldr = ThisOutlookSession.ActiveExplorer.CurrentFolder    'Use this to select current folder
        Set mFldr = ThisOutlookSession.Session.PickFolder   'Use this to let user pick folder
               
        If MsgBox("Are you sure you want to save all the emails from " & mFldr, vbYesNo) = vbNo Then GoTo End_Code
        
        For Each itm In mFldr.Items
            If itm.Class = olMail Then
                strFileName = Left(Format(itm.ReceivedTime, "yyyymmdd hhmmss") & " - " & itm.SenderName & " - " & _
                    StripIllegalChar(itm.Subject), 256) & ".msg"
                itm.SaveAs "C:\" & strFileName, olMSG
            End If
        Next itm
    
    End_Code:
        Set mFldr = Nothing
    
    End Sub
    
    Function StripIllegalChar(StrInput)
        Dim RegX            As Object
        Set RegX = CreateObject("vbscript.regexp")
         
        RegX.Pattern = "[\" & Chr(34) & "\!\@\#\$\%\^\&\*\(\)\=\+\|\[\]\{\}\`\'\;\:\<\>\?\/\,]"
        RegX.IgnoreCase = True
        RegX.Global = True
         
        StripIllegalChar = RegX.Replace(StrInput, "")
    ExitFunction:
        Set RegX = Nothing
         
    End Function

    Dom
    Last edited by Domski; 03-31-2011 at 09:07 AM. Reason: File naming problem
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    537

    Re: Best way to copy all emails without opening each one

    Thanks Dom...heading off to give this a try. Wish me luck....LOL
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0