Removing a store in Outlook using VBA

I have a list of PST files in Excel (with their full path)

a VBA running within excel would  open each PST file (load it) into Outlook and then count the items in each folder and close it.
It would then write in a cell the information from the PST and proceed with the others, until exhaust the list.

The ideal situation, would be to close (remove) any PST file loaded just after have been written the data into the excel spreadsheet. Any hint on how to remove a store (a PST file loaded in Outlook -other than the main PST file) ?

The code for load is pretty straightforward (just Outlk.addstore filepath&name)
but Outlk.removeStore does not work as easy...
Who is Participating?

have you tried
Sub RemovePST() 

 Dim objName As Outlook.NameSpace 

 Dim objFolder As Outlook.Folder 

 Set objName = Application.GetNamespace("MAPI") 

 Set objFolder = objName.Folders.Item("Personal Folders") 

 'Prompt the user for confirmation 

 Dim strPrompt As String 

 strPrompt = "Are you sure you want to remove the Personal Folders file?" 

 If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then 

 objName.RemoveStore objFolder 

 End If 

End Sub

Open in new window

Lau_ForenAuthor Commented:
Thanks Mr.,

I use the following (and is working)

Set remPST = olkNS.folders.GetLast
olkNS.RemoveStore remPST


and what is the problem?
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Lau_ForenAuthor Commented:
None, just only saying thanks and letting you know that in my specific case (where I load a PST file coming from an unknown and inaccessible profile) this do the work.
You're welcome
A solution
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.