Set a Non-Standard Form as the Default Form in a Folder with VBA

D

Dirk

Hi. We have to handle a huge amount of public contactfolders. Now we created
a new contactform and want to change the existing contactitems to this form.
So I wrote a VBA-Script, which changes the messageclass of all items in a
folder and all subfolders. This works fine, but with the same script I want
to set the new form as the default form in all the subfolders. This doesn't
work, because I can't find the right property of the public folder. I'm using
the MAPIFolder object. Is this the right one?
 
K

Ken Slovak - [MVP - Outlook]

MAPIFolder is the correct object, but the property you need to set isn't
exposed in the Outlook object model. You need to set PR_DEF_POST_MSGCLASS
(0x36E5001E), PR_DEF_POST_DISPLAYNAME (0x36E6001E) PT_STRING8 properties

PR_DEF_POST_MSGCLASS gets set to the MessageClass you want as the default
and PR_DEF_POST_DISPLAYNAME gets set to the display name of that form.

You will need to use a lower level API such as CDO 1.21 or Extended MAPI
(C++ or Delphi only) or Redemption (www.dimastr.com/redemption) to do what
you want.
 
D

Dirk

Hi Ken,
thanks for your answer. I never used these lower level APIs before, so I
have to find out how to use them in VBA. Would be nice, if anyone has helpful
hints.
 
K

Ken Slovak - [MVP - Outlook]

With VBA you can forget about Extended MAPI, it's only C++ and Delphi.

CDO is an optional installation for Outlook, it's on the Office CD's.
Redemption is a third party library.

This is what it would look like in CDO code:

'assuming you have CDO installed and a reference set to Microsoft CDO 1.21
Library (CDO.DLL)
' also assuming a folder olFolder has been instantiated:

Dim Folder As MAPI.Folder
Dim oSession As MAPI.Session

Const PR_DEF_POST_MSGCLASS = &H36E5001E
Const PR_DEF_POST_DISPLAYNAME = &H36E6001E

Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False

Set oFolder = oSession.GetFolder(olFolder.EntryID, olFolder.StoreID)

If IsEmpty(oFolder.Fields(PR_DEF_POST_MSGCLASS)) Then
oFolder.Fields.Add(PR_DEF_POST_MSGCLASS, "IPM.Contact.MyContact")
Else
oFolder.Fields(PR_DEF_POST_MSGCLASS).Value = "IPM.Contact.MyContact"
End If

If IsEmpty(oFolder.Fields(PR_DEF_POST_DISPLAYNAME)) Then
oFolder.Fields.Add(PR_DEF_POST_DISPLAYNAME, "My Contact Form")
Else
oFolder.Fields(PR_DEF_POST_DISPLAYNAME).Value = "My Contact Form"
End If

oFolder.Update 'save

oSession.Logoff
 

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