ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 2355|回复: 0

outlook 2003 编程问题

[复制链接]

TA的精华主题

TA的得分主题

发表于 2008-3-14 13:41 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

在用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

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-12-24 13:50 , Processed in 0.025456 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表