cosmarchy
11-26-2010, 12:41 PM
Hi all,
I have the following code which compiles and runs with error but for some reason the function under the .onAction property never gets executed when the menu iten it clicked. Can someone point me in the right direction?
Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection)
Dim objButton As Office.CommandBarButton
On Error GoTo ErrRoutine
' check to see whether we are in a folder that conains mail items
If (Application.ActiveExplorer.CurrentFolder.DefaultItemType = olMailItem) Then
Set objbuttons = CommandBar.Controls.Add(MsoControlType.msoControlButton, , , , True)
With objbuttons
.BeginGroup = True
.Caption = "Custom Function"
.OnAction = "'DoFunc "" & Selection & ""'"
End With
End If
EndRoutine:
Set objButtons = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly Or vbCritical, "Application_ItemContextMenuDisplay"
GoTo EndRoutine
End Sub
Private Function DoFunc(ByVal Selection As Selection)
MsgBox "hello"
End Function
Thanks
I have the following code which compiles and runs with error but for some reason the function under the .onAction property never gets executed when the menu iten it clicked. Can someone point me in the right direction?
Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection)
Dim objButton As Office.CommandBarButton
On Error GoTo ErrRoutine
' check to see whether we are in a folder that conains mail items
If (Application.ActiveExplorer.CurrentFolder.DefaultItemType = olMailItem) Then
Set objbuttons = CommandBar.Controls.Add(MsoControlType.msoControlButton, , , , True)
With objbuttons
.BeginGroup = True
.Caption = "Custom Function"
.OnAction = "'DoFunc "" & Selection & ""'"
End With
End If
EndRoutine:
Set objButtons = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly Or vbCritical, "Application_ItemContextMenuDisplay"
GoTo EndRoutine
End Sub
Private Function DoFunc(ByVal Selection As Selection)
MsgBox "hello"
End Function
Thanks