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...
Lau_ForenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

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

https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/namespace-removestore-method-outlook

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lau_ForenAuthor Commented:
Thanks Mr.,

I use the following (and is working)

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

Best,

Lautaro
0
Rgonzo1971Commented:
and what is the problem?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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.
0
Rgonzo1971Commented:
You're welcome
0
Rgonzo1971Commented:
A solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.