Outlook Execute Macro using Costume Control

  • Thread starter Thread starter Andy via OfficeKB.com
  • Start date Start date
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
 
Have you tried:

objCBB.OnAction = "SaveAttachment"


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Have you tried putting the macro in a regular module, rather than in the
ThisOutlookSession class module?
 
It works! Thanks for your help.

It seems apparent that VBA treats class modules differently from other user
defined modules.
And, it appears that I should perhaps read-up on this subject.

You wouldn't know of a good VBA book that covers this subject?

Thanks again!
Have you tried putting the macro in a regular module, rather than in the
ThisOutlookSession class module?
Yes I have. I cannot get it to work?
[quoted text clipped - 6 lines]
 
Class modules and regular modules *are* different. My book covers a lot of ground, although maybe not that particular nuance with relation to toolbar buttons.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


andjbird via OfficeKB.com said:
It works! Thanks for your help.

It seems apparent that VBA treats class modules differently from other user
defined modules.
And, it appears that I should perhaps read-up on this subject.

You wouldn't know of a good VBA book that covers this subject?

Thanks again!
Have you tried putting the macro in a regular module, rather than in the
ThisOutlookSession class module?
Yes I have. I cannot get it to work?
[quoted text clipped - 6 lines]
own custom button 'HSE Monitors' on the 'Main Menu' commandbar.
However, I
 
Back
Top