Create a new module and paste this source code into it. Change the name of the module to basPublish. If you have any questions, email us at help@codeoftheweek.com
'----------------------------------------------------------------------
'
' Module Name: basPublish
' Written By: C&D Programming Corp.
' Create Date: 11/99
' Copyright: Copyright 1999 by C&D Programming Corp. Source
' code may not be reproduced except for use in a
' compiled executable. All rights reserved. If
' you would like to reprint any or all of this
' code please email us at info@codeoftheweek.com
'----------------------------------------------------------------------
Option Explicit
'
' This routine supports publication of forms to either of the following
' Outlook registry types:
' olOrganizationRegistry
' olPersonalRegistry
'
' sTemplateName should contain the full path and filename of the template
' file (*.OFT) created from the Design mode of Outlook.
'
Public Sub PublishForm(sTemplateName As String, eWhichRegistry As OlFormRegistry)
Dim olApp As Outlook.Application
Dim olFormDesc As Outlook.FormDescription
Dim olItem As Outlook.MailItem
On Error GoTo Handler
If Dir(sTemplateName) = "" Then
Err.Raise 53, "PublishForm", "File is not available. This is usually caused by the filename being incorrect."
End If
' Start up the Outlook application object
Set olApp = New Outlook.Application
' Build item from the template stored on disk
Set olItem = olApp.CreateItemFromTemplate(sTemplateName)
' Get the description information from the form
Set olFormDesc = olItem.FormDescription
' Publish the form in the registry specified by the parameter eWhichRegistry
olFormDesc.PublishForm eWhichRegistry
' Clean up the objects we created.
Set olFormDesc = Nothing
Set olItem = Nothing
Set olApp = Nothing
Exit Sub
Handler:
Set olFormDesc = Nothing
Set olItem = Nothing
Set olApp = Nothing
Err.Raise Err.Number, "PublishForm", Err.Description
End Sub