TIP: Fun with Outlook CommandBars
Many Outlook features simply don't have
programmatic equivalents. A workaround in many cases
is to execute the appropriate Outlook toolbar or
menu command using the CommandBars object from the
Office library. Each command has an ID associated
with it. Use the FindControl method to locate the
CommandBarButton, then the Execute method to run it.
For example, this code -- designed for use in
VBScript on an Outlook form -- displays the Insert
Attachment dialog:
You can also work through the CommandBars menu
hierarchy by specifying the name of each menu and
using its Controls collection in turn. Using
FindControl is more efficient, though. However, in
some cases, such as setting the sending account or
creating a message with stationery, you use the ID
to get the parent menu or command, but then must
look at the text of the individual submenu commands
to determine which to execute. The
Set the sending account and
Create new message with stationery samples
demonstrate this variation.
Note that CommandBars is an object in the Office
object model, not the Outlook object model. If
you're using VB or VBA, make sure your project has a
reference to the Office object library, then try one
of the samples listed below. An important difference
between Outlook and other Office programs is that
the Outlook Application has no CommandBars
collection. Instead, CommandBars is a member of the
Inspector and Explorer objects.
Samples |
CommandBarButton IDs | Notes
| More
Information
|