Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VBScript

How to programmatically create an Outlook home folder page in the Outlook Today style

2.45/5 (7 votes)
4 Aug 2008CPOL3 min read 2  
Outlook Today is a sample of a custom Outlook home folder page. In this article, you will learn how to create such a page in VBScript and in .NET (VB, C#, C++).

Introduction

Outlook Today is a sample of custom Outlook home folder page. In this article, you will learn how to create such a page in VBScript and in .NET (VB, C#, C++).

There are two ways of customizing Outlook Today:

  • It can be modified by the user; you just need to open Outlook Help (see the Help menu) and enter "customize Outlook today" in the Search For field.
  • Or, if you are a developer, you may want to add some functionality to Outlook Today programmatically. Let's dig deeper into this.

Outlook Today is a set of HTML pages that use VBScript to display some Outlook-related information. If you open the Properties window for Personal Folder and navigate to the Home tab, you'll see that the default page address is: res://C:\Program Files\Microsoft Office\OFFICE11\1033\outlwvw.dll/outlook4.htm.

That is, the first Outlook Today page is shown from the resources of some Outlook-related DLL, and this implies that no source code is available for Outlook Today.

In other words, the developer can only replace Outlook Today with a custom page. Let's create such a page: open Notepad and copy / paste the text below:

HTML
<html>
<head> 
<title>VBScript: the first try</title> 
</head> 
<body> 
</body>

Our custom page consists of the HTML tag that contains the head and body tags. The page is empty, as you can see. Now, let's add a button:

HTML
... 
<body> 
<input type="button" value="Go" onClick="greeting()"/> 
</body> 
...

The button caption is "Go", and when you click on the button, the Greeting function is called. Now, let's add the function:

HTML
... 
<head> 
<script type="text/vbscript"> 
 
function greeting() 
   document.write("<p>Hello, developer!</p>") 
end function 
 
</script> 
</head> 
...

This simple function prints a paragraph containing the greeting. Now, we are ready to plug the page into Outlook:

  • Right-click on a folder and choose Properties in the context menu. Note that if the folder is Personal Folders, it means that we replace the Outlook Today page with our custom one.
  • Specify the page location and tick the checkbox that shows the page.

properties.gif

Note that the Address textbox in the screenshot above corresponds to the WebViewUrl property of the MAPIFolder class (Folder in Outlook 2007). Accordingly, the checkbox labeled as "Show home page by default for this folder" corresponds to the WebViewOn property. These properties allow you to set an HTML page for any Outlook folder on the fly. For instance, you can replace the Outlook Today page with your custom one. If you use these properties, you should keep in mind that Outlook 2002 has a well-known bug confirmed by Microsoft: when you set WebViewUrl, the page will show up after the user switches to another folder, and then switches back to the folder with the home page (see the Microsoft website for details).

Here is the page:

vb_script.gif

At this stage, you can move in the following directions:

  • Learn HTML.
  • As always, Google is a good helper: just search for HTML Tutorial.

  • Learn VBScript.
  • Here is a highly recommended guide: MSDN.

However, Outlook Today can display some information about tasks, e-mails / messages, and appointments and meetings. To get these data as well as information about contacts, notes, and other Outlook items, you have to dig into the Outlook object model:

  • Open Outlook
  • Choose Tools | Macros | Visual Basic Editor in the menu or just press Alt+F11
  • In the VB IDE, choose View | Object Browser in the menu or just press F2

vba_reference.gif

Application is the most important Outlook class. It provides the Session property of type NameSpace. The NameSpace class contains Folders. Each Folder (type Folder in Outlook 2007, MAPIFolder in Outlook 2000-2003) contains Items and other Folders. Each Item provides a Class property, the value of which is a constant uniquely identifying every item type: MailItem, TaskItem, ContactItem, etc. To get help on a class or a class member, just press F1. When reading help, pay attention to the availability and other aspects of using a class or class member in VBScript. For instance, Outlook events are not available in VBScript. The following sample function uses the Outlook object model to demonstrate how you can apply the above-mentioned information. The function lists top-level folders in the current Outlook session:

VBScript
function greeting() 
   on error resume next 
 
   dim OutlookApp 
   on error resume next 
   set OutlookApp = GetObject(, "Outlook.Application") 
   if OutlookApp is Nothing then 
      document.write("<p>Hello, developer!</p>") 
      exit function 
   else 
      document.write("<p>Hello, Outlook developer!</p>") 
   end if 
   on error goto 0 
 
   dim folderCount 
   folderCount = OutlookApp.Session.Folders.Count 
   document.write("<p>There are " & folderCount & _
                  " top-level folders in this session. ") 
   document.write("Here they are:</p><ul>") 
   for i = 1 to folderCount 
      dim fldr 
      set fldr = OutlookApp.Session.Folders.Item(i) 
      document.write("<li>" & fldr.Name & "</li>") 
   next 
   document.write("</ul>") 
   document.title = "VBScript: the first try" 
end function 

When I click the button, the function shows the following output in my Outlook 2003. You can do the same in Outlook 2000, 2002 (XP), and Outlook 2007:

first_try.gif

As you can see, it is quite simple.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)