Enable/Disable Commandbar buttons

B

Bodo

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.
 
B

Bodo

Hi Ken,
I modified the sub to enable/dsable the buttons, which works fine now:

Private Sub SetCommandBarButton(ButtonID As OutlookMenuCmdId, ButtonEnabled
As Boolean)
Dim ctrl As Office.CommandBarControl, cmdBar As Office.CommandBar

If Not moOL.ActiveExplorer Is Nothing Then
Set ctrl =
moOL.ActiveExplorer.CommandBars.ActiveMenuBar.FindControl(, ButtonID, , True,
True)
If Not ctrl Is Nothing Then
ctrl.Enabled = ButtonEnabled
End If

For Each cmdBar In moOL.ActiveExplorer.CommandBars
If Not cmdBar Is Nothing Then
'If cmdBar.Type = msoBarTypeMenuBar Then
Set ctrl = cmdBar.FindControl(, ButtonID, , True) '
Auflistung aller Controlls
If Not ctrl Is Nothing Then
ctrl.Enabled = ButtonEnabled
End If
End If
Next
End If

Set cmdBar = Nothing
Set ctrl = Nothing
End Sub


--
Thanks in advance
Bodo


Ken Slovak - said:
Enabled is a Boolean. Use True and False.
 
K

Ken Slovak - [MVP - Outlook]

Thanks in advance for what? Is there a question here or are you just showing
the code that works now?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top