Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2006

Tip: Looking for answers? Try searching our database.

Outlook Execute Macro using Costume Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy - 20 Sep 2006 14:54 GMT
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
Sue Mosher [MVP-Outlook] - 20 Sep 2006 15:36 GMT
Have you tried:

   objCBB.OnAction = "SaveAttachment"

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

> 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
[quoted text clipped - 46 lines]
>
> End Sub
andjbird - 20 Sep 2006 16:38 GMT
Yes I have.  I cannot get it to work?

>Have you tried:
>
[quoted text clipped - 5 lines]
>>
>> End Sub
Sue Mosher [MVP-Outlook] - 20 Sep 2006 18:10 GMT
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
andjbird - 22 Sep 2006 08:05 GMT
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?
[quoted text clipped - 4 lines]
>>>> own custom button 'HSE Monitors' on the 'Main Menu' commandbar.
>>>> However, I
Sue Mosher [MVP-Outlook] - 22 Sep 2006 12:26 GMT
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.

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

> It works!  Thanks for your help.
>
[quoted text clipped - 14 lines]
>>>>> own custom button 'HSE Monitors' on the 'Main Menu' commandbar.
>>>>> However, I
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.