Folder Switch

The FolderSwitch event occurs when the current folder changes in the Explorer, either through a user action or a programmatic change. In the following event procedures, a toolbar button is added to the Standard toolbar in the Application Startup event. If Explorer's current folder is Nwind, the FolderSwitch event makes the New Nwind CommandBarButton visible. Otherwise, the button is hidden on the Standard toolbar. This toolbar button is declared as a CommandBarButton using the WithEvents keyword in the Declarations section of ThisOutlookSession.

'Place these in declarations section of ThisOutlookSession

Public WithEvents objExpl As Outlook.Explorer

Public WithEvents objCBB As Office.CommandBarButton

'Instantiate objExpl and objCBB in Application Startup event procedure

Private Sub Application_Startup() Dim objCB As Office.CommandBar Set objExpl = Application.ActiveExplorer Set objCB = objExpl.CommandBars("Standard") Set objCBB = objCB.Controls.Add(Type:=msoControlButton) With objCBB

.TooltipText = "New Nwind Contact" .Style = msoButtonlconAndCaption .Face Id = 1099 .Caption = "New Nwind" .Visible = False End With End Sub

0 0

Post a comment