Problems using RemoveStore

S

Steve Roberts

I have a form with 2 buttons. Button 1 allows the user to select a folder
using the pickfolder, then using the AddStore, it opens a .pst file with the
name of each of the subfolders in the folder that the user picked. ie user
selects folder test, that contains folder test1 and test 2 it creates/opens
a test1.pst file and a test2.pst file. That part works.

When I click on Button2 to remove the items useing the RemoveStore, it gives
me an error "1491058683 this group of folders is associated with an e-mail
account." and tells me how to manually disconnect from the folders. Below is
the code I am using for the 2 buttons.

Thanks in advance for any suggestions you may have.

Steve


Private Sub btnStep1_Click()

Dim olApp As Outlook.Application
Dim MyNameSpace As Outlook.NameSpace
Dim CurrentFolder As Outlook.MAPIFolder
Dim olNewFolder As Outlook.MAPIFolder
Dim objFolder As Variant

Set olApp = CreateObject("Outlook.Application")
Set MyNameSpace = olApp.GetNamespace("MAPI")
Set CurrentFolder = MyNameSpace.PickFolder

For Each olNewFolder In CurrentFolder.Folders

MyNameSpace.AddStore "H:\Archive_Emails\SteveTest\" & olNewFolder.Name &
".pst"
Set objFolder = MyNameSpace.Folders.GetLast
objFolder.Name = olNewFolder.Name

Next

End Sub


Private Sub btnStep2_Click()

Dim olApp As Outlook.Application
Dim MyNameSpace As Outlook.NameSpace
Dim CurrentFolder As Outlook.MAPIFolder
Dim olNewFolder As Outlook.MAPIFolder

Set olApp = CreateObject("Outlook.Application")
Set MyNameSpace = olApp.GetNamespace("MAPI")
Set CurrentFolder = MyNameSpace.PickFolder
Set olNewFolder = CurrentFolder

For Each olNewFolder In CurrentFolder.Folders

MyNameSpace.RemoveStore olNewFolder

Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top