使用 COM 增益集自訂 OutlookCustomizing Outlook using COM add-ins

建立 COM 增益集包括兩個主要步驟:Creating a COM add-in involves two major steps:

  1. 在動態連結程式庫 (DLL) 的類別模組中實作 IDTExtensibility2 介面。Implement the IDTExtensibility2 interface in a class module of a dynamic link library (DLL).
  2. 註冊 COM 增益集。Register the COM add-in.

實作 IDTExtensibility2 介面Implement the IDTExtensibility2 Interface

IDTExtensibility2 介面由五個事件程序所組成。The IDTExtensibility2 interface consists of five event procedures. 若要在 Visual Basic 程式中實作這個介面,請設定 Microsoft 增益功能設計師的參照,然後將下列陳述式加入類別模組的「宣告」區段:To implement this interface in a Visual Basic program, set a reference to the Microsoft Add-In Designer object library and then add the following statement to the Declarations section of a class module:

Implements IDTExtensibility2

然後,您便能將空白的事件程序加入類別模組的程式碼視窗,並將自己的程式碼加入程序。You can then add the empty event procedures to the code window of the class module and add your own program code to the procedures. 此外,也可以從 Outlook COM 增益集範本複製空白的程序。You can also copy the empty procedures from an Outlook COM Add-in Template.

註冊 COM 增益集Register the COM add-in

為了與 Outlook 搭配使用,必須註冊增益集 DLL。In order to work with Outlook, the add-in DLL must be registered. DLL 的類別 ID 註冊在登錄的 \HKEY_CLASSES_ROOT 樹狀子目錄之下。The DLL's class ID is registered beneath the \HKEY_CLASSES_ROOT subtree in the registry.

此外,關於增益集的資訊也必須加入登錄。In addition, information about the add-in must be added to the registry. 這項資訊提供增益集的名稱、描述、目標應用程式、初始載入行為及連接狀態。This information provides the add-in's name, description, target application, initial load behavior, and connection state.

記事 如果您使用 Microsoft Visual Basic 6.0 或更新版本的開發人員來設計您的 COM 增益集,增益集設計人員將會執行為您註冊 COM 增益集所需的步驟。Note If you use Microsoft Visual Basic 6.0 or later Developer to design your COM add-in, the add-in designer will perform the steps required to register the COM add-in for you.

下列範例顯示範例登錄編輯器 (.reg) 檔案的內容,以說明如何註冊 Outlook COM 增益集。The following example shows the contents of a sample registry-editor (.reg) file that illustrates how to register an Outlook COM add-in.

   [HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\SampleAddIn.AddInIFace]
    "FriendlyName"="Sample Add-in"
    "Description"="Sample Outlook Add-In"
    "LoadBehavior"=dword:00000008

在首次註冊 COM 增益集時,LoadBehavior 可以設定為下列任何標幟。When the COM add-in is first registered, LoadBehavior can be set to any of the following flags.

Value 描述Description
2 2 在啟動時載入。Load at startup. COM 增益集會在 Outlook 啟動時載入和連接。The COM add-in is to be loaded and connected when Outlook starts.
8 8 視需要載入。Load on demand. COM 增益集只會在使用者要求時載入和連接,例如使用 [COM 增益集] 對話方塊。The COM add-in is to be loaded and connected only when the user requests it, such as by using the COM Add-ins dialog box.
16 16 首次連接。Connect first time. COM 增益集會在 COM 增益集已註冊後,使用者首次執行 Outlook 時載入和連接。The COM add-in is loaded and connected the first time the user runs Outlook after the COM add-in has been registered. 下次 Outlook 執行時,COM 增益集則會在使用者要求時載入。The next time Outlook is run, the COM add-in is loaded when the user requests it. 如果您的 COM 增益集修改使用者介面以允許使用者要求 COM 增益集視需要連接 (例如,藉由按一下按鈕),則請使用這個值。Use this value if your COM add-in modifies the user interface to allow the user to request the COM add-in be connected on demand (by clicking a button, for example).

在 COM 增益集已註冊和載入之後,LoadBehavior 值即可與下列兩個標幟之一合併,以指出 COM 增益集的目前連接狀態。After the COM add-in is registered and loaded, the LoadBehavior value can be combined with either of the following two flags to indicate current connection state of the COM add-in.

FlagFlag 描述Description
00 中斷連接Disconnected
1 1 連接Connected

若要連接 COM 增益集,請在 LoadBehavior 中設定 Connected 標幟;清除該標幟則會使 COM 增益集中斷連接。To connect the COM add-in, set the Connected flag in LoadBehavior; clear the flag to disconnect the COM add-in.

The FriendlyName value specifies the name of the COM add-in as it's displayed in the COM Add-in dialog box.The FriendlyName value specifies the name of the COM add-in as it's displayed in the COM Add-in dialog box. The Description value provides additional information about the COM add-in.The Description value provides additional information about the COM add-in.

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.