Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Outlook VBA reference Application Form

Posted on 2004-11-01
Medium Priority
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??
Question by:david_glidewell
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 12463296
I need to do this through VBA Code...  I have to replicate this to over 100 PC's.
LVL 16

Accepted Solution

jimbobmcgee earned 2000 total points
ID: 12463500
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)
        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)

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



Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 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