Outlook Custom Forms and VB.NET- Using VbScript

In this article we will see how to use VB Script with our outlook custom forms how to open this custom form from our Vb .net application. 

For better understanding we take an example:

We will add two controls- label and combo box(cmbTemplate)  in our custom form, combo box is used for template selection, means user use predefined templates ,when user select any template from combo box, the template will  add automatically in message body. 
 

message-html-design-window-in-windows8.jpg

Now next step is to bind combo box with templates, this work will perform with the help of  VB Script

Open vbscript page (click on 'View code' button, Script Editor Page will be open)

We can see various events of this custom form in 'insert Event Handler' window (go to script menu item and click on 'Event Handler...')
 

insert-event-handler-window-in-windows8.jpg
 

Create open event :

Function Item_Open()

 

End Function

   

Now next step is how to use vbscipt for adding items in cmbTemplate

First thing we cannot use control directly in vbscript we  will need to create object of control so we can use these:

  
 

        Set objPage = Item.GetInspector.ModifiedFormPages("Message")

        Set objTemplate = objPage.Controls("cmbTemplate")

Add Items in 
cmbTemplate:
 

        objTemplate.additem "please Call me immedi...."

        objTemplate.additem "Hope you have a good trip...."

        objTemplate.additem "Everything is Ok...."

        objTemplate.additem "I am busy now...."

Next step is Template selection from cmbTemplate:

We can use only click event of any control on this page so that we create Click event of cmbTemplateby writing

Sub cmbTemplate_Click()

 

End sub

 

Apply this code on above event

 

        Set objPage = Item.GetInspector.ModifiedFormPages("Message")

        Set objTemplate = objPage.Controls("cmbTemplate")

        Item.Body=objTemplate.Text

 

Now we can see preview by click on 'Run this Form' button on custom form page menu bar.

We need to publish the form in the forms library or in the folder where you want to use .If you publish it in a public folder, it will be available for all users who have permission to access the folder. If you publish it in a personal folder, it's for your use only.

In this example we publish this form in Personal Forms Library with name 'MyApplicaationForm'.

Call custom form from vb.net side:

For calling this custom form from vb.net form with the help of these lines of code:

Dim outLookApp As New Microsoft.Office.Interop.Outlook.Application()

            Dim objNameSpace As Microsoft.Office.Interop.Outlook.NameSpace = outLookApp.GetNamespace("MAPI")

            Dim objFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = objNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)

            Dim MailItem As Microsoft.Office.Interop.Outlook.MailItem =DirectCast(outLookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem), Microsoft.Office.Interop.Outlook.MailItem)

            MailItem = DirectCast(objFolder.Items.Add("IPM.Note.MyApplicationForm"), Microsoft.Office.Interop.Outlook.MailItem)

            MailItem.Display("IPM.Note.MyApplicationForm")

(Need to add Microsoft.Office.Interop.Outlook library  referance)

Up Next
    Ebook Download
    View all
    Learn
    View all