+ Reply to Thread
Results 1 to 2 of 2

Need a help to extract inbox mails and save in D: drive with sender name

  1. #1
    Registered User
    Join Date
    07-19-2012
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    67

    Need a help to extract inbox mails and save in D: drive with sender name

    Hi

    i have a code for save inbox mails in folder. it works file. it save the mails like "2012-11-30_AM-09-32-05_template".

    But i need to add the file name with sender name or address. Like "2012-11-30_AM-09-32-05_Jack40@excelforum.com_template"

    Please help.

    Here is the code:

    Please Login or Register  to view this content.
    Option Explicit

    Sub SaveAllEmails_ProcessAllSubFolders()

    Dim i As Long
    Dim j As Long
    Dim n As Long
    Dim StrSubject As String
    Dim StrName As String
    Dim StrFile As String
    Dim StrReceived As String
    Dim StrSavePath As String
    Dim StrFolder As String
    Dim StrFolderPath As String
    Dim StrSaveFolder As String
    Dim Prompt As String
    Dim Title As String
    'Dim strID As String
    Dim iNameSpace As NameSpace
    Dim myOlApp As Outlook.Application
    Dim SubFolder As MAPIFolder
    Dim mItem As MailItem
    Dim FSO As Object
    Dim ChosenFolder As Object
    Dim Folders As New Collection
    Dim EntryID As New Collection
    Dim StoreID As New Collection

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set myOlApp = Outlook.Application
    'Set strID = MyMail.EntryID
    Set iNameSpace = myOlApp.GetNamespace("MAPI")
    Set ChosenFolder = iNameSpace.PickFolder
    If ChosenFolder Is Nothing Then
    GoTo ExitSub:
    End If

    Prompt = "Please enter the path to save all the emails to."
    Title = "Folder Specification"
    StrSavePath = BrowseForFolder
    If StrSavePath = "" Then
    GoTo ExitSub:
    End If
    If Not Right(StrSavePath, 1) = "\" Then
    StrSavePath = StrSavePath & "\"
    End If

    Call GetFolder(Folders, EntryID, StoreID, ChosenFolder)

    For i = 1 To Folders.Count
    StrFolder = StripIllegalChar(Folders(i))
    n = InStr(3, StrFolder, "\") + 1
    StrFolder = Mid(StrFolder, n, 256)
    StrFolderPath = StrSavePath & StrFolder & "\"
    StrSaveFolder = Left(StrFolderPath, Len(StrFolderPath) - 1) & "\" '& strID
    If Not FSO.FolderExists(StrFolderPath) Then
    FSO.CreateFolder (StrFolderPath)
    End If

    Set SubFolder = myOlApp.Session.GetFolderFromID(EntryID(i), StoreID(i))
    On Error Resume Next
    For j = 1 To SubFolder.Items.Count
    Set mItem = SubFolder.Items(j)
    StrReceived = ArrangedDate(mItem.ReceivedTime)
    StrSubject = mItem.Subject
    StrName = StripIllegalChar(StrSubject)
    StrFile = StrSaveFolder & StrReceived & "_" & StrName & ".msg"
    StrFile = Left(StrFile, 256)
    mItem.SaveAs StrFile, 3
    Next j
    On Error GoTo 0
    Next i

    ExitSub:

    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

    Function ArrangedDate(StrDateInput)

    Dim StrFullDate As String
    Dim StrFullTime As String
    Dim StrAMPM As String
    Dim StrTime As String
    Dim StrYear As String
    Dim StrMonthDay As String
    Dim StrMonth As String
    Dim StrDay As String
    'Dim strID As String
    Dim StrDate As String
    Dim StrDateTime As String
    Dim RegX As Object

    Set RegX = CreateObject("vbscript.regexp")

    If Not Left(StrDateInput, 2) = "10" And _
    Not Left(StrDateInput, 2) = "11" And _
    Not Left(StrDateInput, 2) = "12" Then
    StrDateInput = "0" & StrDateInput
    End If

    StrFullDate = Left(StrDateInput, 10)

    If Right(StrFullDate, 1) = " " Then
    StrFullDate = Left(StrDateInput, 9)
    End If

    StrFullTime = Replace(StrDateInput, StrFullDate & " ", "")

    If Len(StrFullTime) = 10 Then
    StrFullTime = "0" & StrFullTime
    End If

    StrAMPM = Right(StrFullTime, 2)
    StrTime = StrAMPM & "-" & Left(StrFullTime, 8)
    StrYear = Right(StrFullDate, 4)
    StrMonthDay = Replace(StrFullDate, "/" & StrYear, "")
    StrMonth = Left(StrMonthDay, 2)
    StrDay = Right(StrMonthDay, Len(StrMonthDay) - 3)
    If Len(StrDay) = 1 Then
    StrDay = "0" & StrDay
    End If
    StrDate = StrYear & "-" & StrMonth & "-" & StrDay
    StrDateTime = StrDate & "_" & StrTime
    RegX.Pattern = "[\:\/\ ]"
    RegX.IgnoreCase = True
    RegX.Global = True

    ArrangedDate = RegX.Replace(StrDateTime, "-")
    ExitFunction:
    Set RegX = Nothing
    End Function

    Sub GetFolder(Folders As Collection, EntryID As Collection, StoreID As Collection, Fld As MAPIFolder)

    Dim SubFolder As MAPIFolder

    Folders.Add Fld.FolderPath
    EntryID.Add Fld.EntryID
    StoreID.Add Fld.StoreID
    For Each SubFolder In Fld.Folders
    GetFolder Folders, EntryID, StoreID, SubFolder
    Next SubFolder

    ExitSub:

    Set SubFolder = Nothing

    End Sub


    Function BrowseForFolder(Optional OpenAt As String) As String

    Dim ShellApp As Object

    Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0

    Select Case Mid(BrowseForFolder, 2, 1)
    Case Is = ":"
    If Left(BrowseForFolder, 1) = ":" Then
    BrowseForFolder = ""
    End If
    Case Is = "\"
    If Not Left(BrowseForFolder, 1) = "\" Then
    BrowseForFolder = ""
    End If
    Case Else
    BrowseForFolder = ""
    End Select
    ExitFunction:
    Set ShellApp = Nothing

    End Function





    Please Login or Register  to view this content.
    [/CODE]

  2. #2
    Registered User
    Join Date
    07-19-2012
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    67

    Re: Need a help to extract inbox mails and save in D: drive with sender name

    I have find out..... Thanks....

    it was

    Please Login or Register  to view this content.
    But additionally I want to add numbers before the date using input box… the numbers has been added to each mail.

    For example

    10_2012-11-30_AM-09-32-05_Jack40@excelforum.com_template
    11_2012-11-30_AM-09-32-05_Jack40@excelforum.com_template
    12_2012-11-30_AM-09-32-05_Jack40@excelforum.com_template

    Thanks

    Jack40

+ 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. Save and Rename Attachment based on Sender
    By PicoTTS in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2014, 10:06 PM
  2. Extract XLS* attachments from select mails, save mail info into fields
    By Alteregoist in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-14-2013, 05:35 AM
  3. Get e-mails from outlook inbox
    By Peter1245 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 06-26-2013, 10:49 AM
  4. COPY outlook mails subject, received date, sender details in excel
    By Ratnakar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-27-2012, 10:14 AM
  5. Not getting E-mails in Inbox
    By LilyMarie in forum Outlook Formatting & Functions
    Replies: 3
    Last Post: 03-06-2009, 07:10 AM

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