|
|
Question : Outlook Automation
|
|
I need to write VBA code to do the following:
Create an Outlook archive(pst file) named 'Sent Items Archive' on the user's C drive. Move all items in their default sent items folder to this new archive.
Create an Outlook archive(pst file) named 'Deleted Items Archive' on the user's C drive. Move all items in their default deleted items folder to this new archive.
Create an Outlook archive(pst file) named 'AAA Archive' on the user's C drive. Loop through all folders in their 'Remote Mail' folder and move all new(not matching a list I have) folders/items to this new archive.
Compact the new archive folders.
I know that I can create a new archive using the following code:
Dim oApplication As Outlook.Application Dim oMapi As NameSpace Dim oSentItemsFolder As MAPIFolder Dim oDeletedItemsFolder As MAPIFolder Dim oOtherFolder As MAPIFolder Dim oAAAArchive As MAPIFolder Dim oSentArchive As MAPIFolder Dim oDeleteArchive As MAPIFolder Dim oItems As Items Dim ocurItem As MailItem Dim opstFile As MAPIFolder
Set oApplication = New Outlook.Application Set oMapi = oApplication.GetNamespace("MAPI") Set oSentItemsFolder = oMapi.GetDefaultFolder(olFolderSentMail) Set oDeletedItemsFolder = oMapi.GetDefaultFolder(olFolderDeletedItems)
oMapi.AddStore ("C:\AAA Archive.pst") oMapi.AddStore ("C:\Sent Items Archive.pst") oMapi.AddStore ("C:\Deleted Items Archive.pst")
.....
but the new archives get called 'Personal Folder'. I need to specify the names.
I also would appreciate some thoughts on looping throught the 'Remote Mail' folder.
Thanks,
perkc
|
Answer : Outlook Automation
|
|
I manually created a PST file ("C:\MyStuff.pst") with the name "blahblah". This code changed it:
Public Sub CheckFolders() Dim myOlApp Dim myNameSpace Set myOlApp = GetObject(, "Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") myNameSpace.Folders("blahblah").Name = "SetName" End Sub
|
|
|
|