Excel Access to .PST File in Outlook

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,291
Office Version
  1. 365
Platform
  1. Windows
I have used VBA to download all email address I have sent and received emails from in my inbox.

Now I want to do the same for my .PST archive file.

My Current code is.
Rich (BB code):
Sub GetFromInbox()
Application.ScreenUpdating = False

    Dim olApp As Outlook.Application
    Dim olNs As NameSpace
    Dim Fldr As MAPIFolder
    Dim olMail As MailItem
    Dim i As Integer
    Dim x As Integer
    Dim y As Integer
    Dim internalcount As Integer
    

    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
    Set Fldr = Fldr.Folders("2011").Folders("inbox")
    UserForm1.Show False
    
    i = 1
    x = 1
    
    Sheets("New").Cells.ClearContents
    y = Fldr.Items.Count
    
    For Each olMail In Fldr.Items
        UserForm1.TextBox1.Value = x & "  //  " & y
        UserForm1.Repaint
        
            Sheets("New").Cells(i, 1).Value = olMail.SenderName
            Sheets("New").Cells(i, 2).Value = olMail.SenderEmailAddress
            i = i + 1
        
            x = x + 1
        On Error Resume Next
    Next olMail
    UserForm1.Hide
    
    Set Fldr = Nothing
    Set olNs = Nothing
    Set olApp = Nothing

End Sub


how do I set the folder to my .pst file

.PST Folder name is

2010/Inbox

Any advise would be appreciated.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Sorry to bump this but I still haven't managed to solve this.

All i need to know is how to reference the PST file.

I currently have

Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set Fldr = Fldr.Folders("2011").Folders("inbox")

This gets me access to the INBOX/2011/INBOX folder (the tree of folders directly under my inbox)

Howver I have a PST file called 2010 and no matter what I have tried i cannot reference it
 
Upvote 0
Try this code to give you the correct folder path:

Code:
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
On Error Resume Next
Set Fldr = olNs.PickFolder
If Not Fldr Is Nothing Then
  MsgBox Fldr.FolderPath
Else
  MsgBox "You didn't pick a folder"
End if
 
Upvote 0
Outputs \\2010\inbox

I changed my code to

Code:
    Set myFldr = olNs.GetDefaultFolder(olFolderInbox)
    Set myFldr = myFldr.Folders("2010").Folders("inbox")

I get runtime error '-2147352567(80020009)'"
Array index out of bounds
 
Upvote 0
If it's an archive then it presumably isn't a folder of your default olFolderInbox.

You can access your StoreID and EntryID using the code I originally gave which means you can then use the GetFolderFromID method of the Namespace object if you don't want to simply use the PickFolder method:

Code:
Dim app As Outlook.Application
Dim nms As Outlook.Namespace
Dim fld As Outlook.Folder



Set app = GetObject(, "Outlook.Application")

Set nms = app.GetNamespace("MAPI")

Set fld = nms.PickFolder


Debug.Print "StoreID: " & fld.StoreID
Debug.Print "EntryID: " & fld.EntryID

Then hardcode in your routine:

Code:
Set fld = nms.GetFolderDromID("Output_From_EntryID","Output_From_SToreID")
 
Upvote 0
I understand your first reply better now.
I have added the "Select folder" into the main routine and this is working perfectly.

Thanks for your help on this
 
Upvote 0
Maybe you can help with another problem.


When doing the same for the "Sent Items" I am trying to gather the sent to email addresses.

However if the email is a reply then the property .to contains the persons name and not the full email address.

Any ideas if these is a property of the olmail object that will always contain a full email address??
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top