A
Andy via OfficeKB.com
Having read some of the postings on this website, I have managed to define my
own custom button 'HSE Monitors' on the 'Main Menu' commandbar. However, I
have not been able set-up the command button to execute the required macro.
The required macro being 'SaveAttachment' in the 'ThisOutlookSession' module.
Can anyone help. I have listed the code I have tried so far. I am using
Excel 2000.
Private Sub Application_Startup()
Dim objOL As Outlook.Application
Dim colCB As Office.CommandBars
Dim objCB As Office.CommandBar
Dim objCBMenu As Office.CommandBarPopup
Dim objCBMenuCB As Office.CommandBar
Dim objCBB As Office.CommandBarButton
Set objOL = CreateObject("Outlook.Application")
Set colCB = objOL.ActiveExplorer.CommandBars
Set objCB = colCB.Item("Menu Bar")
For Each Control In objCB.Controls
If Control.Caption = "HSE Monitors" Then GoTo ByPass
Next Control
Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, Temporary:=True)
With objCBMenu
.Caption = "HSE Monitors"
Set objCBMenuCB = .CommandBar
Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton,
Temporary:=True)
objCBB.Caption = "Check Monitor Emails"
objCBB.OnAction = "ThisOutlookSession.SaveAttachment"
End With
ByPass:
Set objButton = Nothing
Set objBar = Nothing
Set objOL = Nothing
Set colCB = Nothing
Set objCB = Nothing
Set objCBMenu = Nothing
Set objCBMenuCB = Nothing
Set objCBB = Nothing
End Sub
own custom button 'HSE Monitors' on the 'Main Menu' commandbar. However, I
have not been able set-up the command button to execute the required macro.
The required macro being 'SaveAttachment' in the 'ThisOutlookSession' module.
Can anyone help. I have listed the code I have tried so far. I am using
Excel 2000.
Private Sub Application_Startup()
Dim objOL As Outlook.Application
Dim colCB As Office.CommandBars
Dim objCB As Office.CommandBar
Dim objCBMenu As Office.CommandBarPopup
Dim objCBMenuCB As Office.CommandBar
Dim objCBB As Office.CommandBarButton
Set objOL = CreateObject("Outlook.Application")
Set colCB = objOL.ActiveExplorer.CommandBars
Set objCB = colCB.Item("Menu Bar")
For Each Control In objCB.Controls
If Control.Caption = "HSE Monitors" Then GoTo ByPass
Next Control
Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, Temporary:=True)
With objCBMenu
.Caption = "HSE Monitors"
Set objCBMenuCB = .CommandBar
Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton,
Temporary:=True)
objCBB.Caption = "Check Monitor Emails"
objCBB.OnAction = "ThisOutlookSession.SaveAttachment"
End With
ByPass:
Set objButton = Nothing
Set objBar = Nothing
Set objOL = Nothing
Set colCB = Nothing
Set objCB = Nothing
Set objCBMenu = Nothing
Set objCBMenuCB = Nothing
Set objCBB = Nothing
End Sub