????? ????? Office COM ??????? ???????? ???????? Visual Basic .NET

?????? ????????? ?????? ?????????
???? ???????: 302896 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

????? Microsoft Office 2000 ?????????? ?????? ????? ????? ????? ????? ????? ????????? ???????? ?????? ? ?????? ?? ??????? Office. ???? ??? ??????? ???????? ????? COM ????????. ?????? ??? ??????? ??????? ???????? ?? COM Office ??? ??????? ???? ????? ??? ???? ????? ????? COM Office ??????? ???????? ???????? Microsoft Visual Basic .NET.

????? IDTExensibility2

????? COM ???????? ????? ?? ???? COM ??? ??????? ?? ????? ???????? ?????? ActiveX (DLL) ???? ???? ?????? ??????? IDTExensibility2 ??? ?? ???? ?? ????? ????? ???? Microsoft ??????? ???????? (Msaddndr.dll). ???? ????? COM ???????? ??? ?? ??? ??????? ? ??? ?? ???? ?????? ?? ?? ?????? ??? ????? ??.

OnConnection

??? ????? OnConnection ???? ??? ?????? ??????? ???????? COM. ??????? ???????? ???? ?????? ?? ??? ??? ??????? ?????? ???????? ??????? ?? ?? ???? ???????. ??? ?? ????? OnConnection ?????, ??????? ???????? ?? ???? ???? ??????. ??? ?? ????? ????? ??? ??????? ?????? ?????? ????????? ?????? ?? ???? ??????? ???????? ?? ????? ??????.

???? OnConnection ???????? ?????? ???????:
  • ??????? - ???? ??? ???? ??????? ??????.
  • ConnectMode - ???? ???? ????? ??????? ???????? ?????. ???? ?? ???? ????? ??????? ???????? ?????? ???????:
    • ??? ?????? ext_cm_AfterStartup - ??????? ???????? ?????? ???????? ??????? ?? ???? ?????? ????? COM ????????.
    • ???? ext_cm_CommandLine - ??????? ???????? ?? ??? ???????. ???? ??? ?? ??? ????? ??? ??? ????? ??????? ???????? ?? COM ???????? Office.
    • ???? ext_cm_External - ??????? ???????? ?????? ????? ????? ???? ???????. ???? ??? ?? ??? ????? ??? ??? ????? ????? COM ???????? ?? Office ?????????.
    • ??? ????? ext_cm_Startup - ??????? ???????? ?? ??? ?????? ??? ??? ????? ???????. ????? ??? ?????? ??? ????? ?? ???????.
  • AddInInst - ???? ??? ???? COMAddIn ???? ???? ??? ??? ??????? ???????? ??? ?????? ????? COM ???????? ??????? ??????.
  • ???? - ???? ??? ??? ????? ???? ???????? ??????? ?? ??? ????????.

OnDisconnection

??? ????? OnDisconnection ????? ??? ??? ??????? ???????? COM ? ??? ????? ????? ?? ???????. ??????? ???????? ??? ????? ????? ????? ?? ??????? ?? ??? ????? ???????? ??? ?? ??? ??????? ??? ??????? ??? ??????? ??????.

???? OnDisconnection ??????? ???????:
  • RemoveMode - ???? ???? ????? ??????? ???????? ?? ??? ?????. ??????? ???????? ???? ??? ??????? ?????? ???????:
    • ?? ??? ??????? ext_dm_HostShutdown - ??????? ???????? ??? ????? ??????? ??????.
    • ext_dm_UserClosed - ??????? - ?? ?? ??? ??????? ?? ??? ???????? ??????? ?? ??????? ??? ???? ????.
  • ???? - ???? ??? ??? ????? ???? ???????? ??????? ?? ??? ????????.

OnAddInsUpdate

??? ????? OnAddInsUpdate ??? ???????? ?? ????? COM ????????? ??????? ????????. ????? ???? ???? ????? ???????? COM ??? ????? ?? ????? ?? ??????? ?????? ??? ??? ?????.

OnStartupComplete ? OnBeginShutdown

?? ???? OnStartupComplete ??????? OnBeginShutdown ??? ??? ??????? ?????? ?? ??? ????? ???? ?? ?????? ??? ???? ????? ??? ??????? ????? ????? ?? ????? ????? ???? ?? ???????. ??? ??????? OnStartupComplete ??? ??? ??????? ???????? ???? ????? ??? ??????? ??????? OnBeginShutdown ??? ?? ???? ??? ????? ?????? ??????? ???????? ????? ????? ???????.

??? ????? ???????? ??????? ?????? ??? ???? ???? ??? ????? ??? ???????, ??? ???? ??????? ??????? ?????? ??????? ????? ???? ????? ?????? ?? OnConnection ? OnDisconnection.

??????? ???????? COM ???????

???????? ??? ????? COM ?????? ????? ???????? COM ????? ????? ???? ?? ?? ????? Office ???? ??? ?????. ????? ???? ?? ????? ???? ??????? ???????? ???? ????? ??????? ???? ???????? ProgID ????? ?? ??? ??? ????? ??? ?????? ??????:
HKEY_CURRENT_USER\Software\Microsoft\Office\ OfficeApp \Addins\ ProgID
??????? ???????? ???? ????? ????? ?? ??? ?????? ??????? ?? ??? ??? ????? ???? ????. ???????? ??? ???? ??????? ???????? ??? ????? ???? ??????? ??????? ???????? ???? DWORD ????
LoadBehavior
. ???? ??? ?????? ??????? ???????? ??? ?????? ?? ??? ??????? ?????? ? ?????? ????? ?? ?????? ?? ????? ???????:
  • 0 = ??? ??????? - ??? ??????.
  • 1 = ???? - ?? ??????.
  • 2 = bootload - ??????? ??? ??? ???????.
  • 8 = demandLoad - ????? ??? ??? ???? ?? ??? ????????.
  • 16 = ConnectFirstTime - ??????? ??? ????? ??? (??? ??? ??????? ??????).
?????? ????????? ??????? ?? 0x03 (???? | Bootload).

??? ????? ????? ??????? ???????? ???? ???? ?????? IDTExtensibility2 ???? DWORD ????
CommandLineSafe
?????? ?? ??? ???? ??????? ???????? ????? ???????? ???? ?? ????? ????? ??????. ???? ???? 0x00 ??? False ????? ???? 0x01 ??? True.

????? ????? ??????? ???????? COM ???????? Visual Basic .NET

??? ???? ?????? COM Office ????? ????? ???????? COM ?? ??????? ?????? ???? ?? ?????? ?????? ????? Office ???? ???? ??? ??????? COM. ????? ????? ????? ???????? ?? COM ?? Visual Basic .NET ????? ?? ???? ???? ??????? ???????? ?? .NET ??? ?? ????? ?? ????? COM (??? ??????? Office) ??? ???? COM ??????? ??????? ????????.

?????? ????? ???????? COM ?? Visual Basic .NET ???? ??????? ???????:
  1. ?? Visual Basic .NET ????? "????? ???" ???????.
  2. ????? ???? ??? ????? ????? ???? ???? IDTExtensibility2. ????? ??????? ??????? ???????? ??????? ??? ????? ?????? ??? ??? ???????? ???????.
  3. ????? ???? ??? ????? ?????? Microsoft Office. ????? ??????? ??????? ???????? ??????? ??? ????? ?????? ??? ??? Office.
  4. ????? ??? ???? ?? ????? ????? ????? IDTExtensibility2.
  5. ?? ????? ????? ??? ????? ? ????? ????? COM interop. ?????? ????? ????? ???? ???? ??????? ???? ??????? ??? ?? ?? ???????? ?? interop COM. ????? ??????? Regasm.exe ????? ???? .NET interop COM.
  6. ????? ??????? ??????? ???? ???? ?????? ??? ??????? Office ?? ????? ??????? ????????.
????? ?????? ?????? ???? ??????? ??????? ?? ????? ????? ????? .NET ?? ????? Addin ????????. ???? ??? ??? ????? "????? ???????? ???????" ???? ?????? ?? ????? ????? ???????? COM ?? .NET.

????? ???????? ??????? ?????? ????? Visual Basic .NET ??? ????? ?? ??? ??????? ???? ???? ??????? IDTExtensibility2. ?? ????? ??? skeleton ????? ????? ????? IDTExtensibility ?????. ????? ??? ??????? ????? ????????? ???????? ??????? ?Office. ??????? ??????? ??????? ?? ???? ???? ????? Interop COM ??????. ??? ????? ??? ????? (.snk) ????? ? ?????? ????? ?? ??? AssemblyKeyfile ?? Assemblyinfo.vb.

?? ??????? ????? ??? ??????? ?????? ????? ????? ???? ????? ????????? ???? ?? ??????? ???????? COM ??? ????? ??????? ????. ????? ????? ??? ??????? ??? ???? ?? ???.

???? ???? ?????

  1. ?? ??????? ??? ?? Microsoft Visual Studio .NET ???? ??? ???? ?? ???? ??? ???????.
  2. ?? ???? ?????? ????? ???? ????? ?????? ???? ??? Project ????? ??? ???????? ???????? ??????? ?? ??? ???? ??????? ???????? ????????.
  3. ???? MyCOMAddin ??? ?? ??? ??????? ???????? ?? ???? ??? ?????.
  4. ??? ???? "????? ???????? ???????" ???? ??????? ???????:
    1. ??? ?????? 1 ??? ????? ??????? ???????? ???????? Visual Basic ?? ???? ??? ??????.
    2. ?? ?????? 2 ? ???? ????????? ?????? ??????? ?? ???? ??? ??????:
      • Microsoft Word
      • Microsoft PowerPoint
      • Microsoft Outlook
      • Microsoft Excel
      • Microsoft Access
    3. ??? ?????? 3 ????? ??? ???? ?????? ??? ??????? ???????? ?? ???? ??? ??????.

      ?????? ???? ??? ???? ??????? ???????? ?? ???? ?????? ????? COM ???????? ?? ????? Office.

    4. ?? ?????? 4 ? ??? ???? ???????? ???????? ?? ???? ??? ??????.
    5. ???? ??? ?????.
  5. ????? ??? ??????? ??? ??? ???????:
    Dim WithEvents MyButton As CommandBarButton 
  6. ????? ????????? ???????? ????? ????? IDTExtensibility2 ?? ??? ??????? ??? ???:
        Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
            On Error Resume Next
            ' Notify the user you are shutting down, and delete the button.
            MsgBox("Our custom Add-in is unloading.")
            MyButton.Delete()
            MyButton = Nothing
    
        End Sub
    
        Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
            '
        End Sub
    
        Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
    
            Dim oCommandBars As CommandBars
            Dim oStandardBar As CommandBar
    
            On Error Resume Next
            ' Set up a custom button on the "Standard" command bar.
            oCommandBars = applicationObject.CommandBars
            If oCommandBars Is Nothing Then
                ' Outlook has the CommandBars collection on the Explorer object.
                oCommandBars = applicationObject.ActiveExplorer.CommandBars
            End If
    
            oStandardBar = oCommandBars.Item("Standard")
            If oStandardBar Is Nothing Then
                ' Access names its main toolbar Database.
    
                oStandardBar = oCommandBars.Item("Database")
    
            End If
    
            ' In case the button was not deleted, use the exiting one.
            MyButton = oStandardBar.Controls.Item("My Custom Button")
            If MyButton Is Nothing Then
    
                MyButton = oStandardBar.Controls.Add(1)
                With MyButton
                    .Caption = "My Custom Button"
                    .Style = MsoButtonStyle.msoButtonCaption
    
                    ' The following items are optional, but recommended. 
                    ' The Tag property lets you quickly find the control 
                    ' and helps MSO keep track of it when more than
                    ' one application window is visible. The property is required
                    ' by some Office applications and should be provided.
    
                    .Tag = "My Custom Button"
    
                    ' The OnAction property is optional but recommended. 
                    ' It should be set to the ProgID of the add-in, so that if
                    ' the add-in is not loaded when a user clicks the button,
                    ' MSO loads the add-in automatically and then raises
                    ' the Click event for the add-in to handle. 
    
                    .OnAction = "!<MyCOMAddin.Connect>"
    
                    .Visible = True
                End With
            End If
    
            ' Display a simple message to show which application you started in.
            MsgBox("Started in " & applicationObject.Name & ".")
    
    
            oStandardBar = Nothing
            oCommandBars = Nothing
    
    
        End Sub
    
        Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
    
            On Error Resume Next
            If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
               Call OnBeginShutdown(custom)
    
            applicationObject = Nothing
    
    
        End Sub
    
        Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
    
    
            MsgBox("On Connection In MyAddin")
            applicationObject = application
            addInInstance = addInInst
    
    
            ' If you aren't in startup, manually call OnStartupComplete.
            If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
               Call OnStartupComplete(custom)
    
        End Sub
    
    
        Private Sub MyButton_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles MyButton.Click
            MsgBox("Our CommandBar button was pressed!")
        End Sub
    					
  7. ????? ??????? ??????? ???????? COM. ?????? ????? ???? ??????? ???????:
    1. ?? ??????? ????? ? ???? ??? ????? MyCOMAddin. ???? ?? ????? ??????? ???????? COM ???? ??? .NET ?????? interop COM.
    2. ??? ????? ??? ??????? Office ???? ?????? ???????? ???? ??????? ???????? (??? ???? ??????? Microsoft Word ?? Microsoft Excel).
    3. ??? ??????? ???????? ??? ? ????? ????? OnConnection ????? ???? ?????. ????? ??????? ???? ??????? ??????? ????? OnStartupComplete ????? ???? ????? ????. ??????? ???? ???????.
    4. ???? ?? ??????? ???????? ????? ?? ???? ???? ?? ??????? ????????? "?? ???? ????" ??? ???? ??????? ???????.
    5. ???? ??? ?? ???? ????. ??? ?????? ??? ????? ??? ?? ??? ??????? ???????? ????? ???? ?????. ??????? ???? ???????.
    6. ?? ?????? ????? Office.
    7. ????? ??????? OnBeginShutDown ??????? ????? ? ??????? ??????? ???? ?????. ??????? ???? ??????? ?????? ????? ????????.

?????

?????? ??? ??????? ?????? ??? ????? ????? COM ???????? ???? ??? ??? ??????? ????? ?????? ?? "????? ??????? ?? Microsoft:
190253INFO: ????? VB6 ?? ???? ?? VB5
?????? ??? ???? ?? ????????? ??? ????? ?????? ???????? ??? ??? ??????? Microsoft Internet Explorer? ?? ?????? ????? Microsoft ??????? ??? ?????:
http://msdn2.microsoft.com/en-us/ie/default.aspx

http://support.microsoft.com/iep
(c) ??? ???? Microsoft ???? ???? ?????. ????????? ??? ???? R. Sawant ? Microsoft Corporation.

???????

???? ???????: 302896 - ????? ??? ??????: 04/?? ?????/1427 - ??????: 11.3
????? ???
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Office Excel 2003
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Office Outlook 2003
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Office PowerPoint 2003
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft Office Word 2003
  • Microsoft Word 2002 Standard Edition
????? ??????: 
kbmt kbautomation kbhowtomaster KB302896 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????302896

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com