View Single Post
  #1  
Old September 20th 06, 02:54 PM posted to microsoft.public.outlook.program_vba
Andy via OfficeKB.com
external usenet poster
 
Posts: 1
Default Outlook Execute Macro using Costume Control

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

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...g-vba/200609/1

Ads