在用VB6做OUTLOOK 2003一个自定义按钮时用到问题,就时在outlook中显示不出按钮,请高手指点,也时刚学VB,outlook也刚用,以下时部分代码: Option Explicit ' IDTExtensibility2 is the interface that hooks up our COM addin to Outlook Implements IDTExtensibility2 ' main application object - passed to us from Outlook in the OnConnection method Dim goOutlook As Outlook.Application ' handle inspector events so we can detect when user is creating a new mail message Public WithEvents goInspectors As Outlook.Inspectors ' this is used to detect when our custom commandbar button is clicked Public WithEvents goButton As Office.CommandBarButton ' how to send the message Public Enum SendType cnOutbox ' save in the outbox cnDraft ' save in the drafts folder End Enum ' ' OnConnection - this is called by Outlook when the addin is first connected (loaded). ' Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant) On Error GoTo Err_Handler ' store outlook application object so we can use it later Set goOutlook = Application ' store the inspectors object so we can detect when the user ' is composing a new mail message Set goInspectors = goOutlook.Inspectors Exit Sub Err_Handler: ' any handle error End Sub Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant) End Sub Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant) End Sub Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant) On Error Resume Next ' release objects Set goOutlook = Nothing Set goInspectors = Nothing Set goButton = Nothing End Sub Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant) End Sub ' ' NewInspector - a new inspector window is being created. Make sure ' our controlbar button is either visible (for mail windows) or ' hidden (for all other windows). ' Private Sub goInspectors_NewInspector(ByVal Inspector As Outlook.Inspector) ' Resume next since the FindControl call will generate an ' error if the button can not be found. We don't want to ' end, but add the button to the controlbar. On Error Resume Next ' see if our button already exist on the commandbar Dim oBar As Office.CommandBar Set oBar = Inspector.CommandBars("Standard") Set goButton = oBar.FindControl(Type:=msoControlButton, Id:=oBar.Controls("Send mass mail").Id) ' if it does not, then add it to the controlbar If goButton Is Nothing Then Set goButton = oBar.Controls.Add(1) With goButton .Caption = "Send mass mail" .Style = MsoButtonStyle.msoButtonIconAndCaption .Tag = "Send mass mail" .OnAction = "!<Massmail.Connect>" End With End If ' use the same icon as the Send button for our button Dim oSendButton As Office.CommandBarButton Set oSendButton = oBar.FindControl(Type:=msoControlButton, Id:=oBar.Controls("Send").Id) ' only try setting the properties if found the Send button If Not oSendButton Is Nothing Then goButton.Style = msoButtonIconAndCaption goButton.FaceId = oSendButton.FaceId End If ' only show our button if this is a mail message If Inspector.CurrentItem.Class = olMail Then goButton.Visible = True Else goButton.Visible = False End If End Sub ' ' Click - this is called when our custom commandbar button is clicked. ' Private Sub goButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean) On Error GoTo Err_Handler ' get the mail message object the user is creating ' we do this by first getting the inspector and then the inspectors mail item Dim oInspector As Inspector Set oInspector = goOutlook.ActiveInspector ' get the current mail item Dim oCurMail As Outlook.MailItem Set oCurMail = oInspector.CurrentItem ' you could check the Subject field here and warn the user ' if it is empty ' display the mass mail dialog, this is where the user specifies ' a distribution file that contains the list of emails Dim dlgSend As New dlgSend dlgSend.Show vbModal ' send the mass mail is user pressed the Send button If dlgSend.gbSend Then If dlgSend.optOutbox Then SendMassMail oCurMail, dlgSend.txtFile.Text, cnOutbox Else SendMassMail oCurMail, dlgSend.txtFile.Text, cnDraft End If End If ' done using the send dialog Unload dlgSend Err_Handler: ' error handling End Sub |