带有On.Action的VBA outlook调用方法
通过一个上下文菜单选项,在一个名为Tickets的类中进行管理,我想调用一个名为TEmail的方法,该方法是在管理菜单事件的同一个类中定义的 我尝试使用实例、类、名称等定义许多不同类型的.OnAction属性,但没有成功。我不能运行TEmail代码带有On.Action的VBA outlook调用方法,vba,class,methods,outlook,commandbar,Vba,Class,Methods,Outlook,Commandbar,通过一个上下文菜单选项,在一个名为Tickets的类中进行管理,我想调用一个名为TEmail的方法,该方法是在管理菜单事件的同一个类中定义的 我尝试使用实例、类、名称等定义许多不同类型的.OnAction属性,但没有成功。我不能运行TEmail代码 Public WithEvents AppEvent As Outlook.Application Private Sub AppEvent_ItemContextMenuDisplay(ByVal CommandBar As Office.Com
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
解决方案是创建一个事件处理程序
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