我参考:
http://support.microsoft.com/default.aspx?scid=kb%3Bzh-cn%3B238228
【如何生成 VisualBasic 中 Office 2000 COM 加载宏】
进行自己的程序的开发。其中ADD-IN的connect连接器核心代码如下:
Option Explicit   Dim oXL As Object
   Dim withevents MyButton As Office.CommandBarButton   Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
    ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
    ByVal AddInInst As Object, custom() As Variant)
      On Error Resume Next
      MsgBox "My Addin started in " & Application.Name
   
      Set oXL = Application
   
      Set MyButton = oXL.CommandBars("Standard").Controls.Add(1)
         With MyButton
            .Caption = "My Custom Button"
            .Style = 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 there is more than
          ' one application window 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, such that if
          ' the add-in is not loaded when a user presses the button,
          ' MSO loads the add-in automatically and then raises
          ' the Click event for the add-in to handle.            .OnAction = "!<" & AddInInst.ProgId & ">"            .Visible = True
         End With
   
   End Sub   Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As _
      AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
      On Error Resume Next
      MsgBox "My Addin was disconnected by " & _
         IIf(RemoveMode = ext_dm_HostShutdown, _
         "Excel shutdown.", "end user.")
      
      MyButton.Delete
      Set MyButton = Nothing
      Set oXL = Nothing
    End Sub   Private Sub MyButton_Click(ByVal Ctrl As Office.CommandBarButton, _
     CancelDefault As Boolean)
      MsgBox "Our CommandBar button was pressed!"
   End Sub问题就是,上面的第3行:
Dim withevents MyButton As Office.CommandBarButton在我的VB里面编译不通过,报告【不是源事件对象】
只能改成:Dim MyButton As Office.CommandBarButton,才能通过。但是这样我又无法处理自己添加的按钮的点击事件了。
我已经查遍GOOGLE,MSDN,CSDN了。拜求达人解答。望赐教!谢谢。