+ Reply to Thread
Results 1 to 6 of 6

Amending Existing Code for Extracting Information from Outlook Folder

Hybrid View

XOR LX Amending Existing Code for... 10-09-2014, 08:48 AM
romperstomper Re: Amending Existing Code... 10-09-2014, 08:53 AM
XOR LX Re: Amending Existing Code... 10-09-2014, 10:02 AM
romperstomper Re: Amending Existing Code... 10-09-2014, 10:05 AM
XOR LX Re: Amending Existing Code... 10-09-2014, 10:14 AM
romperstomper Re: Amending Existing Code... 10-09-2014, 10:32 AM
  1. #1
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Amending Existing Code for Extracting Information from Outlook Folder

    Hi all.

    I recently received a solution to my question here:

    http://www.excelforum.com/excel-prog...-a-folder.html

    regarding looping through subfolders of a particular folder in my Outlook session and extracting certain information.

    I now need to be able to do precisely the same operation, but this time the folder that I want to run the code on is not one of my default Outlook session folders, but rather a .pst file that I currently have open in Outlook via an external hard drive.

    Here is the code that romperstomper kindly provided me with, which works great when the folder in question is one from my own Outlook session:

    Sub Download_Outlook_Mail_To_Excel()
        Dim olApp                 As Outlook.Application
        Dim Folder                As Outlook.MAPIFolder
        Dim SubFolder             As Outlook.MAPIFolder
        Dim MailBoxName           As String
        Dim Pst_Folder_Name       As String
        Dim rngOut                As Range
    
        MailBoxName = "John.Doe@XMail.com"
        Pst_Folder_Name = "Deleted Items"
        Set olApp = GetObject(, "Outlook.Application")
        Set Folder = olApp.Session.Folders(MailBoxName).Folders(Pst_Folder_Name)
    
        If Folder = "" Then
            MsgBox "Invalid Data in Input"
            GoTo end_lbl1:
        End If
    
        Application.ScreenUpdating = False
    
        Sheets(1).Activate
    
        Range("A1").Value = "From"
        Range("B1").Value = "Subject"
        Range("C1").Value = "Received"
        Range("D1").Value = "Text"
        Set rngOut = Range("A2")
    
        PrintFolderList Folder, rngOut
    end_lbl1:
        Application.ScreenUpdating = True
    
    End Sub
    Sub PrintFolderList(fdr As Outlook.MAPIFolder, rng As Range)
        Dim i                     As Long
        Dim itm
        Dim fSub                  As Outlook.MAPIFolder
        fdr.Items.Sort "Received"
    
        For Each itm In fdr.Items
            With itm
                rng.Resize(, 4).Value = Array(.SenderName, .Subject, .ReceivedTime, .Body)
            End With
            Set rng = rng.Offset(1)
        Next itm
        If fdr.Folders.Count > 0 Then
            For Each fSub In fdr.Folders
                Debug.Print rng.Address, fSub.Name
                PrintFolderList fSub, rng
            Next fSub
        End If
    
    End Sub
    Can anyone tell me how to adjust the code to work for this case? I have tried amending the lines:

    MailBoxName = "John.Doe@XMail.com"
    and

    Pst_Folder_Name = "Deleted Items"
    to various things, but nothing seems to work.

    Help appreciated as always.

    Cheers
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,106

    Re: Amending Existing Code for Extracting Information from Outlook Folder

    What does the top level folder name look like in the Outlook window with the .pst file loaded?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Amending Existing Code for Extracting Information from Outlook Folder

    Not sure what you mean by "top-level", sorry.

    My Navigation Pane appears to give "John.Doe@XMail.com" and the name of the .pst file I am accessing as being at the same "level" within the folder structure, though neither is a subfolder of the other.

    Is that what you meant?

    Regards

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,106

    Re: Amending Existing Code for Extracting Information from Outlook Folder

    Did you replace the "John.Doe@XMail.com" in the code with the exact caption of the .pst file as it appears in the Outlook navigation pane?

  5. #5
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Amending Existing Code for Extracting Information from Outlook Folder

    Ouch. For some reason, no. I instead changed the Pst_Folder_Name to that...

    Just tried what you said and works great.

    Stupidity reigns supreme. Think it's time I picked up that manual!

    Thanks a lot again!

    Cheers

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,106

    Re: Amending Existing Code for Extracting Information from Outlook Folder

    Glad to help.

+ 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. [SOLVED] Extend Existing Code to Loop Through All Subfolders in a Folder
    By XOR LX in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2014, 08:47 AM
  2. [SOLVED] Amending existing macro (removing restrictions)
    By index9 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2013, 01:47 AM
  3. Amending Sharepoint List in Outlook
    By MGK in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 08-13-2012, 03:44 PM
  4. Help amending existing marco for a criteria search on a database
    By howardjo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2008, 07:01 AM
  5. [SOLVED] Amending an existing function
    By Paydog4 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-27-2006, 11:55 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