Thanks,
Lando
------------------------------------------------
Sub Arc()
' MAPI property tags for aging properties
Const CdoPR_AGING_PERIOD = &H36EC0003
Const CdoPR_AGING_GRANULARITY = &H36EE0003
Const CdoPR_AGING_PATH = &H6856001E
Const CdoPR_AGING_ENABLED = &H6857000B
Const CdoPR_AUTOARCHIVE_TYPE = &H685E0003
Const CdoPR_AGING_AGE_FOLDER = &H6857000B
Const CdoPR_CONTAINER_CLASS = &H3613001E
' Properties for aging granularity
Const AG_MONTHS = 0
Const AG_WEEKS = 1
Const AG_DAYS = 2
' Declare variables
Dim objSession As MAPI.Session
Dim objInfoStore As Object
'Dim objInboxFolder As MAPI.Folder
'Dim colFolders As MAPI.Folders
' Initialize variables
Set objSession = Nothing
Set objInboxFolder = Nothing
' Create CDO session and logon
Set objSession = New MAPI.Session
' CDO session logon
objSession.Logon "", "", ShowDialog:=True, NewSession:=False
Set objInfoStore = objSession.InfoStores.Item(1)
Set objRootFolder = objInfoStore.RootFolder
Set colFolders = objRootFolder.Folders
Set objFolCalendar = objSession.GetDefaultFolder(CdoDefaultFolderCalendar)
Set objFolContacts = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolDeleted =
objSession.GetDefaultFolder(CdoDefaultFolderDeletedItems)
Set objFolJournal = objSession.GetDefaultFolder(CdoDefaultFolderJournal)
Set objFolNotes = objSession.GetDefaultFolder(CdoDefaultFolderNotes)
Set objFolSent = objSession.GetDefaultFolder(CdoDefaultFolderSentItems)
Set objFolTasks = objSession.GetDefaultFolder(CdoDefaultFolderTasks)
Set objFolInbox = objSession.GetDefaultFolder(CdoDefaultFolderInbox)
Set objFolOutbox = objSession.GetDefaultFolder(CdoDefaultFolderOutbox)
For Each objFolder In colFolders
' Get hidden message collection
Set objHiddenMessages = objFolder.HiddenMessages
' Loop through the hidden messages collection
For Each objMessage In objHiddenMessages
Select Case objFolder.ID
Case objFolInbox.ID
Case objFolOutbox.ID
Case objFolJournal.ID
Case objFolContacts.ID
Case objFolCalendar.ID
Case objFolDeleted.ID
Case objFolNotes.ID
Case objFolTasks.ID
Case objFolSent.ID
Case Else
If Not objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then
objMessage.Add "IPC.MS.Outlook.AgingProperties"
End If
' Change the autoarchive mode (none,default,param)
objMessage.Fields.Item(CdoPR_AUTOARCHIVE_TYPE).Value = 0
' Change aging properties to 14 months/weeks/days
objMessage.Fields.Item(CdoPR_AGING_PERIOD).Value = 3
' Change aging granularity to days
objMessage.Fields.Item(CdoPR_AGING_GRANULARITY).Value = AG_MONTHS
' Change the path to the archive file
objMessage.Fields.Item(CdoPR_AGING_PATH).Value = "C:\Temp\archive.pst"
' Enable aging for this folder
objMessage.Fields.Item(CdoPR_AGING_ENABLED).Value = True
' Enable aging age for this folder
objMessage.Fields.Item(CdoPR_AGING_AGE_FOLDER).Value = True
' Update hidden message
objMessage.Update True, True
'End If
End Select
Next
Next
End Sub
I never worked with HiddenMessages so far and can´t find the class in
the Objectbrowser. Is it the Messages class, too?
If so, not objMessage, but objMessages has the Add method, and you´d
need to re-design your code: You´d need to loop through the whole
collection for searching the specified type and add it only if there is
no match. Maybe the loop have not to be if you can use the Item method?
BTW: If this is the complete code why do you check the objFolder.ID in
each objMessage loop?
--
Viele Grüße
Michael Bauer
"Lando" <la...@noemails.com> wrote in message
news:#DOErU3G...@tk2msftngp13.phx.gbl...
As Michael said, the error is coming from Message.Add, which doesn't exist.
Once you get your Messages collection from HiddenMessages you would use
Messages.Add.
There's some information about the properties for archiving at
www.cdolive.com/cdo10.htm. Also, take a look at
http://www.cdolive.com/archiveviewer.htm, which uses those properties to
view autoarchive settings. It does a lot of what you want to do.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Michael Bauer" <mi...@t-online.de> wrote in message
news:%23KlJCf9...@TK2MSFTNGP10.phx.gbl...
I know I'm asking alot but does anyone have some sample code or could modify
my code below that would apply archive settings to a folder or all folders
in a mailbox with the values I chose? It seems I keep missing things I think
a savvy programmer would catch and could do much faster than I could ever
hope to.
Thanks again for all your help! I really appreciate it!
Lando
----------------------------------------------
Sub LandoCode()
' MAPI property tags for aging properties
Const CdoPR_AGING_PERIOD = &H36EC0003
Const CdoPR_AGING_GRANULARITY = &H36EE0003
Const CdoPR_AGING_PATH = &H6856001E
Const CdoPR_AGING_ENABLED = &H6857000B
Const CdoPR_AUTOARCHIVE_TYPE = &H685E0003
Const CdoPR_AGING_AGE_FOLDER = &H6857000B
Const CdoPR_CONTAINER_CLASS = &H3613001E
Const CdoPR_AGING_FILENAME = &H6856001E
' Properties for aging granularity
Const AG_MONTHS = 0
Const AG_WEEKS = 1
Const AG_DAYS = 2
' Declare variables
Dim objSession As MAPI.Session
Dim objInfoStore As Object
Dim objHiddenMessages As MAPI.Messages
Dim objMessage As MAPI.Message
Dim objFields As MAPI.Fields
' Initialize variables
Set objSession = Nothing
Set objInboxFolder = Nothing
' Create CDO session and logon
Set objSession = New MAPI.Session
' CDO session logon
objSession.Logon "", "", ShowDialog:=True, NewSession:=False
' Get the inbox folder of a mailbox
Set objFolder = objSession.Inbox
' Get the hidden messages collection
Set objMessages = objFolder.HiddenMessages
' Loop through the hidden messages
For Each objMessage In objMessages
' Check the message class
If objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then
MsgBox (objMessage.Type)
Set objFields = objMessage.Fields
Set objField = objFields.Item(CdoPR_AGING_FILENAME)
MsgBox (objField.Value)
' For Each objField In objFields
' MsgBox (objField.Value)
' Next
End If
Next
End Sub
"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:ee1IBYa...@TK2MSFTNGP14.phx.gbl...
The next may be a problem. We are using Outlook 2003 in cached mode. We use
cached mode because the Junk-Email filter requires it be turned on to
function. I can set the autoarchive settings and when cached mode is OFF the
settings are correct. However if I turn cached mode ON the settings are
incorrect. Is there some way to refresh this information in the cached
profile via VBA or some other way?
Thanks ahead of time for everyones help. You guys are the just awesome!
Thanks,
Lando
"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:ee1IBYa...@TK2MSFTNGP14.phx.gbl...
for the first you can easily adapt this template:
' <Sample: Loop through the Outlook folders hierarchy for handling _
each folder item>
Public Sub HandleAllItems(oRoot As Outlook.NameSpace)
LoopFolders oRoot.Folders, True
End Sub
Private Sub LoopFolders(oFolders As Outlook.Folders, _
ByVal bRecursive As Boolean _
)
Dim oFld As Outlook.MAPIFolder
' Loop through all folders.
For Each oFld In oFolders
' Loop through folder items
LoopItems oFld.Items
If bRecursive Then
' Call this function again for going _
deeper into the object hierarchy.
LoopFolders oFld.Folders, bRecursive
End If
Next
End Sub
Private Sub LoopItems(oItems As Outlook.Items)
Dim obj As Object
For Each obj In oItems
Select Case True
Case TypeOf obj Is Outlook.MailItem
HandleMailItem obj
Case TypeOf obj Is Outlook.ContactItem
' Another method for handling ContactItems
' etc.
End Select
Next
End Sub
Private Sub HandleMailItem(oItem As Outlook.MailItem)
' Do s.th. with the object.
End Sub
' </Sample>
For the second please wait for Ken :-)
--
Viele Grüße
Michael Bauer
"Lando" <la...@noemails.com> wrote in message
news:#dorGvdH...@TK2MSFTNGP12.phx.gbl...
One thing to note with Michael's example is that it is using the Outlook
object model and not CDO 1.21 code to iterate the folders. Similar code
could be written using CDO code using the Folders collection of each loaded
InfoStore in the Session.InfoStores collection and iterating each Folder
object.
And conversion from CDO to Outlook or vice versa is by getting the folder
EntryID (ID in CDO) along with StoreID and then using
NameSpace.GetFolderFromID or Session.GetFolder.
If the specific InfoStore is a default Exchange mailbox the synching of the
offline store (OST) and the mailbox on the server would take place at
scheduled intervals. To synch at different intervals you could find the
CommandBarButton that corresponds to Send/Receive All and use that button's
Execute method. That should synch. For public folders you need to set the
store to download public folders, set the email account to synch the folders
of interest and to add the public folders to the public folder favorites
folder.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Michael Bauer" <mi...@t-online.de> wrote in message
news:ehQQO5dH...@TK2MSFTNGP10.phx.gbl...
> Gee, thanks, Michael :)
please, what is the meaning of "Gee"?
Thanks,
Lando
"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:OT55PymH...@TK2MSFTNGP12.phx.gbl...
>Sub Arc()
>
>' MAPI property tags for aging properties
>Const CdoPR_AGING_PERIOD = &H36EC0003
>Const CdoPR_AGING_GRANULARITY = &H36EE0003
>Const CdoPR_AGING_PATH = &H6856001E
>Const CdoPR_AGING_ENABLED = &H6857000B
>Const CdoPR_AUTOARCHIVE_TYPE = &H685E0003
>Const CdoPR_AGING_AGE_FOLDER = &H6857000B
>Const CdoPR_CONTAINER_CLASS = &H3613001E
>
>' Properties for aging granularity
>Const AG_MONTHS = 0
>Const AG_WEEKS = 1
>Const AG_DAYS = 2
>
>' Declare variables
>Dim objSession As MAPI.Session
>Dim objInfoStore As Object
>'Dim objInboxFolder As MAPI.Folder
>' CDO session logon
>'Dim colFolders As MAPI.Folders
>Set objInboxFolder = Nothing
>Set objSession = New MAPI.Session
|||DIM objMessage
|||SET objMessage
|||SET objMessageHidden as objMessage
>-----Original Message-----
>I am trying to set the default autoarchive settings for
user created folders
>within Outlook 2003 using the code below yet I keep
getting the error Object
>doesn't support this property or method on the line:
objMessage.Add
>"IPC.MS.Outlook.AgingProperties". Does anyone know what
is wrong here? I
>would also like to change it to be recursive in case of
subfolders. Any
>revised sample code would be appreciated.
>
>Thanks,
>Lando
>------------------------------------------------
>>
>
>.
>
Each folder's aging properties are stored in a hidden item in the folder (in
the HiddenMessages collection of that folder). When you are accessing the
store using cached mode you have access to the OST file and not directly to
the Exchange mailbox. The OST should synch to the mailbox at scheduled
intervals and a send/receive all usually does that synch.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Lando" <la...@noemails.com> wrote in message
news:umO1Irn...@TK2MSFTNGP15.phx.gbl...
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Michael Bauer" <mi...@t-online.de> wrote in message
news:%23TyX4Wn...@TK2MSFTNGP10.phx.gbl...
--
Viele Grüße
Michael Bauer
"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:uUeWfNzH...@TK2MSFTNGP09.phx.gbl...
Also, when accessing the OST file while in cached mode the archive settings
are NOT correct. If I take the user out of cached mode the archive settings
are displayed correctly. The send/receive all does NOT sync the archive
settings. The server settings differ from the local OST file settings. Is
there a way to syncronize these?
Another way to do this may be to apply archive settings using Outlook's
built-in archive properties rather than using CDO to access the mail store
information. For example, I right-click on a folder and set the autoarchive
properties and click ok. Is there a way to do this via VB rather than using
the folders autoarchive property menus?
Thanks in advance for the help!
Lando
"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:O%237MfNzH...@TK2MSFTNGP09.phx.gbl...
1) As I said you can easily adapt my sample. Just change the object
types from Outlook types into Mapi types. For Mapi the hierarchy is
Session/InfoStores/InfoStore/Folders/Folder/Messages.
If you have done that and still get errors then it would be helpful for
us if you say what type of errors you get.
2) Ken thinks: gee, but I still don´t know the answer :-)
3) No way via the OOM. There would be a way with a lot of Win32 APIs and
a separate (EXE) thread. My strongly recommendation: Forget it :-)
--
Viele Grüße
Michael Bauer
"Lando" <la...@noemails.com> wrote in message
news:#bvluU0H...@TK2MSFTNGP14.phx.gbl...
I don't know of any ways to get around your cached problem if a synch isn't
matching the server side and local OST settings. The only thing I see in
your code that could be a problem is the assumption that the archive
properties you are accessing always will exist in the folders. In many cases
the properties won't exist until they are created. So you might want to try
getting a property or setting it and if you get an error then using the Add
method to add those properties to the folder.
For a CDO sample to iterate folders just use Michael's Outlook example and
change the types to CDO types. Otherwise the principles are identical.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Lando" <la...@noemails.com> wrote in message
news:%23bvluU0...@TK2MSFTNGP14.phx.gbl...
"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:Ozo2$NAIFH...@TK2MSFTNGP10.phx.gbl...
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Lando" <la...@noemails.com> wrote in message
news:uLEDKiCI...@TK2MSFTNGP09.phx.gbl...
Thanks,
Rich
--
rbuckleyPosted from http://www.pcreview.co.uk/ newsgroup access
This is some code I have for changing the auto-archive settings:
Sub ReadFolderAgingProperties()
Dim objFolder As MAPI.Folder
Dim objMessage As MAPI.Message
Dim objSession As MAPI.Session
Dim objField As MAPI.Field
Set objSession = New MAPI.Session
objSession.Logon , , , False
Set objFolder =
objSession.GetFolder(Application.ActiveExplorer.CurrentFolder.EntryID)
For Each objMessage In objFolder.HiddenMessages
If objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then
' Change the autoarchive mode (none,default,param)
objMessage.Fields.Item(CdoPR_AUTOARCHIVE_TYPE).Value = 0
' Change aging properties to 14 months/weeks/days
objMessage.Fields.Item(CdoPR_AGING_PERIOD).Value = 3
' Change aging granularity to days
objMessage.Fields.Item(CdoPR_AGING_GRANULARITY).Value = AG_MONTHS
' Change the path to the archive file
objMessage.Fields.Item(CdoPR_AGING_PATH).Value =
"C:\Temp\archive.pst"
' Enable aging for this folder
objMessage.Fields.Item(CdoPR_AGING_ENABLED).Value = True
' Enable aging age for this folder
objMessage.Fields.Item(CdoPR_AGING_AGE_FOLDER).Value = True
' Update hidden message
objMessage.Update True, True
End If
Next
Set objFolder = Nothing
Set objMessage = Nothing
objSession.Logoff
Set objSession = Nothing
End Sub
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
' MAPI property tags for aging properties
Public Const CdoPR_AGING_PERIOD = &H36EC0003
Public Const CdoPR_AGING_GRANULARITY = &H36EE0003
Public Const CdoPR_AGING_PATH = &H6856001E
Public Const CdoPR_AGING_ENABLED = &H6857000B
' Properties for aging granularity
Public Const AG_MONTHS = 0
Public Const AG_WEEKS = 1
Public Const AG_DAYS = 2
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", True ,False
Set objInfoStore = objSession.InfoStores.Item(2)
Set objRootFolder = objInfoStore.RootFolder
Set colFolders = objRootFolder.Folders
Set objFolCalendar =
objSession.GetDefaultFolder(CdoDefaultFolderCalendar)
Set objFolContacts =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolDeleted
=objSession.GetDefaultFolder(CdoDefaultFolderDeletedItems)
Set objFolJournal =
objSession.GetDefaultFolder(CdoDefaultFolderJournal)
Set objFolNotes = objSession.GetDefaultFolder(CdoDefaultFolderNotes)
Set objFolSent =
objSession.GetDefaultFolder(CdoDefaultFolderSentItems)
Set objFolTasks = objSession.GetDefaultFolder(CdoDefaultFolderTasks)
Set objFolInbox = objSession.GetDefaultFolder(CdoDefaultFolderInbox)
Set objFolOutbox = objSession.GetDefaultFolder(CdoDefaultFolderOutbox)
For Each objFolder In colFolders
'msgbox "here"
' Get hidden message collection
Set objHiddenMessages = objFolder.HiddenMessages
' Loop through the hidden messages collection
For Each objMessage In objHiddenMessages
'msgbox "here2"
' Check if the message class points to an aging message
If objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then
' Change aging properties to 14 months/weeks/days
objMessage.Fields.Item(CdoPR_AGING_PERIOD).Value = 22
' Change aging granularity to days
objMessage.Fields.Item(CdoPR_AGING_GRANULARITY).Value = AG_DAYS
' Change the path to the archive file
objMessage.Fields.Item(CdoPR_AGING_PATH).Value = "c:\archive.pst"
' Enable aging for this folder
objMessage.Fields.Item(CdoPR_AGING_ENABLED).Value = True
' Update hidden message
objMessage.Update True, True
End If
Next
Next
I thought this might be an issue with Cached mode, but this is really
irrelevant with .pst files, and it occurs with this off or on.
I'm stumped. I was! After I wrote that, I dug around some more. This same
issues was discussed in April:
Basically, Outlook 2003 stores this setting in a new MAPI property. Set a
MAPI.Field object reference using this constant:
Const CdoPR_AGING_PATH_V2 = &H6859001E '0x6859001E
Now you should be able to read and write it properly. Note the changes to
the other properties as per that thread.
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
I need your help on the topic at hand....
our company is short on $$$ but we too need to impliment auto archiving
and your CDO Code seems to be a way to help our company....
I see the posted codes you all have submitted but if it is working can
some one explain to me how can i use this to do the same for my
company....
all help is welcomed...
Tony...
--
Goku316Posted via http://www.officehelp.in - <a href="http://www.officehelp.in">Microsoft Office Software</a>
I know this thread has stopped for a while but I had been working for
this for a while, dropped and is working on it again out of interest.
Would appreciate it if anyone can input on this.
Does anybody know how to distinguish, in Outlook 2003, the difference in
settings between a folder with specific AutoArchive settings and 1 that
is using the "Archive items...using the default settings." option?
BTW, anybody knows of a source with more complete information on this
subject?
Thanks.
*** Sent via Developersdex http://www.developersdex.com ***