0

使用在名为“ Tickets ”的类中管理的上下文菜单选项,我想调用在管理菜单事件的同一类中定义的名为“ TEmail ”的方法。

我尝试使用实例、类、名称等定义许多不同类型的 .OnAction 属性,但没有成功。我无法运行“TEmail”代码。

Public WithEvents AppEvent As Outlook.Application

Private Sub AppEvent_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection)

    Dim objButton As Office.CommandBarButton

    On Error GoTo ErrRoutine

    Set objButton = CommandBar.Controls.Add(msoControlButton)

    With objButton
        .BeginGroup = True
        .Caption = "Test-TEmail"
        .FaceID = 1000
        .Tag = "T-Email"
        .OnAction = "TEmail"
    End With

EndRoutine:
    Exit Sub

ErrRoutine:
    MsgBox Err.Number & " - " & Err.Description, vbOKOnly Or vbCritical, "Application_ItemContextMenuDisplay"
    GoTo EndRoutine
End Sub

Public Sub TEmail()
  ... my code ...
End Sub
4

1 回答 1

0

解决方案是创建一个事件处理程序。

Public WithEvents AppEvent As Outlook.Application 
Public WithEvents myControl As CommandBarButton

Private Sub AppEvent_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, _
  ByVal Selection As Selection) 

    Dim objButton As Office.CommandBarButton 
    Dim oExp As Outlook.Explorer

    Set oExp = Outlook.ActiveExplorer

    On Error GoTo ErrRoutine 

    Set myControl = CommandBar.FindControl(, , "OpenForm")

    If myControl Is Nothing Then
        Set myControl = CommandBar.Controls.Add(msoControlButton) 
        With myControl
         .Caption = "TEmail"
         .FaceID = 59
         .Style = msoButtonIconAndCaption
         .Tag = "TEmail"
         .Visible = True
        End With
    End If
    ' ... 
End Sub 

Private Sub myControl_Click(ByVal Ctrl As Office.CommandBarButton, _
  CancelDefault As Boolean)
    TEmail
End Sub

Public Sub TEmail() 
    ' ... 
End Sub 
于 2014-09-23T20:17:46.153 回答