
June 29th 07, 06:26 PM
posted to microsoft.public.outlook.program_addins
|
|
Enable/Disable Commandbar buttons
Enabled is a Boolean. Use True and False.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Bodo" wrote in message
...
Hi,
The follwing code snipset is from a COM Add-in that I've build for Outlook
2002 SP3 . The addin enables/disables some commandbarbuttons from Outlook
commandbars depending on the users selection of a folder.
e.g.:
If the user clicks on public folder "A" commandbarbutton "Forward" from
"Actions"-Menu should be disabled.
If the user clicks on any other folder button "Forward" from
"Actions"-Menu
should be enabled.
I picked the "Forward" button-id (=356) from Outlook-spy.
This works ok, but when the users selects an item from the folder "A"
where
Forward-button should be disabled, the button actually gets enabled.
Enum MenuStatus
Enable = 1
Disable = 0
End Enum
Enum OutlookMenuCmdId
menuCmdID_Speichernunter = 748
menuCmdID_ImportExport = 2577
menuCmdID_Drucken = 4
menuCmdID_Kopieren = 19
menuCmdID_InOrdnerverschieben = 1679
menuCmdID_InOrdnerkopieren = 1676
menuCmdID_AlsvCardweiterleiten = 5573
menuCmdID_Weiterleiten = 356
menuCmdID_KontextDrucken = 2521
End Enum
Private Sub moActiveExplorer_FolderSwitch()
If moActiveExplorer.CurrentFolder.Name =
cPublicFolder_LV_Mitarbeiter Then
Outlook_EnableDisable_MenuItems (MenuStatus.Disable)
Else
Outlook_EnableDisable_MenuItems (MenuStatus.Enable)
End If
End Sub
Private Sub moActiveExplorer_SelectionChange()
If moActiveExplorer.CurrentFolder.Name =
cPublicFolder_LV_Mitarbeiter Then
Outlook_EnableDisable_MenuItems (MenuStatus.Disable)
Else
Outlook_EnableDisable_MenuItems (MenuStatus.Enable)
End If
End Sub
Public Sub Outlook_EnableDisable_MenuItems(EnableDisable As MenuStatus)
Dim oCmdBarMenu As Office.CommandBar
Dim oBarCrls As Office.CommandBarControls
Dim ocmdBarPopup As Office.CommandBarPopup
Dim Enabled As Boolean, CommandsInfo As String
On Error GoTo Outlook_EnableDisable_MenuItems_Err
Enabled = (EnableDisable = Enable)
SetCommandBarButton menuCmdID_Speichernunter, Enabled
SetCommandBarButton menuCmdID_AlsvCardweiterleiten, Enabled
SetCommandBarButton menuCmdID_Drucken, Enabled
SetCommandBarButton menuCmdID_ImportExport, Enabled
SetCommandBarButton menuCmdID_InOrdnerkopieren, Enabled
SetCommandBarButton menuCmdID_InOrdnerverschieben, Enabled
SetCommandBarButton menuCmdID_KontextDrucken, Enabled
SetCommandBarButton menuCmdID_Kopieren, Enabled
SetCommandBarButton menuCmdID_Weiterleiten, Enabled
Outlook_EnableDisable_MenuItems_Exit:
Exit Sub
Outlook_EnableDisable_MenuItems_Err:
MsgBox "Fehler in Outlook-Addin: " & Err.Description, vbExclamation
Resume Outlook_EnableDisable_MenuItems_Exit
End Sub
Private Sub SetCommandBarButton(ButtonID As OutlookMenuCmdId,
ButtonEnabled
As Boolean)
Dim oBarButton As Office.CommandBarButton
Set moOfficeCmdBars = moActiveExplorer.CommandBars
Set oBarButton = moOfficeCmdBars.FindControl(, ButtonID)
If Not oBarButton Is Nothing Then
oBarButton.Enabled = ButtonEnabled
End If
Set oBarButton = Nothing
Set moOfficeCmdBars = Nothing
End Sub
Appreciate any clues.
--
Thanks in advance
Bodo
|