Solved

Outlook VBA reference Application Form

Posted on 2004-11-01
467 Views
Last Modified: 2008-02-01
I need to add a button control to the MailItem form in Outlook.
I need to run vba code from this button.

I have figured out how to add buttons to the main outlook form, but not the mailitem form..

How do I reference that form and add a button control??
0
Question by:david_glidewell
    2 Comments
     

    Author Comment

    by:david_glidewell
    I need to do this through VBA Code...  I have to replicate this to over 100 PC's.
    0
     
    LVL 16

    Accepted Solution

    by:
    The following will add a toolbar to a programmatically created mailitem

        Sub MyMail()
       
            Dim oMail As MailItem
            Dim oBar As CommandBar
            Dim oBtn As CommandBarButton
       
            Set oMail = Application.CreateItem(olMailItem)
               
           
            oMail.Display
           
            Set oBar = oMail.GetInspector.CommandBars.Add("My Command Bar", , , True)
            Set oBtn = oBar.Controls.Add(, , , , True)
           
            oBtn.Caption = "My Button"
            oBtn.Picture = LoadPicture("x:\mypath\myvalid16x16image.ico")
            oBtn.OnAction = "myModule.myMacro"
           
            oBtn.Visible = True
            oBar.Visible = True
           
            Set oBtn = Nothing
            Set oBar = Nothing
            Set oMail = Nothing
           
        End Sub

    If you want to add to the currently open item, remove

            Set oMail = Application.CreateItem(olMailItem)

    and change

            Set oBar = oMail.GetInspector.CommandBars.Add("My Command Bar", , , True)

    to
     
            Set oBar = ActiveInspector.CommandBars.Add("My Command Bar", , , True)

    HTH

    J.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now