Copying Calendar Folder to new .PST - How to Reference New .PST to copy and close.

G

Guest

I am creating a sub to open a shared .pst, copy the default calendar to the shared .PST, and then close it. However, I have found no way to directly reference the second .PST folder tree as there are now two folders named "Personal Folders". The code follows

Sub Export_Calendar(
Dim CurrentOutLook As New Outlook.Applicatio
Dim CurrentNameSpace As Outlook.NameSpac

' Return a reference to the MAPI layer
Set CurrentOutLook = Outlook.Applicatio
Set CurrentNameSpace = CurrentOutLook.GetNamespace("MAPI"

' Locate Calendar Folder to Cop
Set MyRootFolder = CurrentNameSpace.Folders("Personal Folders"
Set MyCalFolder = MyRootFolder.Folders("Calendar"

' Open/Create Shared .PS
CurrentNameSpace.AddStore ("c:\my documents\" & CurrentNameSpace.CurrentUser & ".pst"

' Copy Calendar Folder from first .PST to second .PS
' Set ExportCalFolder = MyCalFolder.CopyTo(????
' CurrentNameSpace.CloseStore (ExportTopFolder

End Su

I tried 'Set ExportRootFolder = CurrentNameSpace.AddStore("path"+filename)' to get a reference to the new store's root folder, but that did not work. Indicated "variable mistype"

Every example that I saw of the "CopyTo" method dealt with copying one folder to another within the same store, not to a different store

There must be someway to refer to the 2 "stores" seperately. I think I just need some way to reference the second store so that I can copy the Calendar Folder to it and then use "removestore" on it. Thanks
 
K

Ken Slovak - [MVP - Outlook]

Each PST will be a different object in the NameSpace.Folders
collection. If only 2 PSTs are open and you aren't running under
Exchange where you would have a public folders store opened you would
only have 2 MAPIFolder objects in NameSpace.Folders.

If you get the default Calendar folder using:
Set MyCalFolder =
CurrentNameSpace.GetDefaultFolder(olFolderCalendar)

You are assured you have the default PST file's set of folders.
Assigning MyRootFolder to MyCalFolder gets you the default PST file:
Set MyRootFolder = MyCalFolder.Parent

From there you can compare your default top level folder to the one
from the other PST file:
If MyRootFolder.StoreID <> CurrentNameSpace.Folders(1).StoreID
Then
'not default
Of course you would set up a loop to test all the loaded
NameSpace.Folders. Another test could be to compare the folder.EntryID
properties.




Ken Edwards said:
I am creating a sub to open a shared .pst, copy the default calendar
to the shared .PST, and then close it. However, I have found no way
to directly reference the second .PST folder tree as there are now two
folders named "Personal Folders". The code follows:
Sub Export_Calendar()
Dim CurrentOutLook As New Outlook.Application
Dim CurrentNameSpace As Outlook.NameSpace

' Return a reference to the MAPI layer.
Set CurrentOutLook = Outlook.Application
Set CurrentNameSpace = CurrentOutLook.GetNamespace("MAPI")

' Locate Calendar Folder to Copy
Set MyRootFolder = CurrentNameSpace.Folders("Personal Folders")
Set MyCalFolder = MyRootFolder.Folders("Calendar")

' Open/Create Shared .PST
CurrentNameSpace.AddStore ("c:\my documents\" &
CurrentNameSpace.CurrentUser & ".pst")
' Copy Calendar Folder from first .PST to second .PST
' Set ExportCalFolder = MyCalFolder.CopyTo(????)
' CurrentNameSpace.CloseStore (ExportTopFolder)

End Sub


I tried 'Set ExportRootFolder =
CurrentNameSpace.AddStore("path"+filename)' to get a reference to the
new store's root folder, but that did not work. Indicated "variable
mistype".
Every example that I saw of the "CopyTo" method dealt with copying
one folder to another within the same store, not to a different store.
There must be someway to refer to the 2 "stores" seperately. I
think I just need some way to reference the second store so that I can
copy the Calendar Folder to it and then use "removestore" on it.
Thanks
 

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