This article describes how to use Outlook 10.0 Object
Library to list the commands on the
File menu in Visual Basic .NET.
Create Sample to List the File Menu Commands
- Start Microsoft Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- Click Visual Basic Projects under Project Types, and then click Console Application under Templates. By default, Module1.vb is created.
- Add a reference to the Microsoft Outlook 10.0 Object
Library and the Microsoft Office 10.0 Object Library. To do this, follow these
steps:
- On the Project menu, click Add Reference.
- Click the COM tab.
- Click Microsoft Outlook 10.0 Object
Library, and then click Select
- Click Microsoft Office 10.0 Object
Library, and then click Select
- Click OK. If you are prompted to generate wrappers for the libraries that
you selected, click Yes.
- In the Code window, replace the default code with the
following code:
Imports System.Reflection
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Get Mapi NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:
' Get ActiveExplorer.
Dim oExp As Outlook.Explorer = oApp.ActiveExplorer()
'oExp.Display()
' Get menu bar.
Dim oCmdBars As Office._CommandBars = oExp.CommandBars
Dim oCmdBar As Office.CommandBar = oCmdBars("Menu Bar")
Console.WriteLine(oCmdBar.Name)
Dim oBarCrls As Office.CommandBarControls = oCmdBar.Controls
'Dim oBP As Office.CommandBarPopup
'For Each oBP In oBarCrls
' Console.WriteLine(oBP.Caption)
'Next
' Get File menu.
Dim oBPop As Office.CommandBarPopup = oBarCrls("File")
Console.WriteLine(oBPop.Caption)
oBarCrls = oBPop.Controls
' Loop each menu.
Dim oBn As Office.CommandBarControl
For Each oBn In oBarCrls
Console.WriteLine(oBn.Caption)
Next
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oExp = Nothing
End Sub
End Module
- Modify the code where you see the TODO comments.
- Press F5 to build and to run the application.
- Verify that the commands on the File menu are displayed.
For more information, visit the following Microsoft
Developer Network (MSDN) Web site: