• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

Outlook VBA reference Application Form

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
david_glidewell
Asked:
david_glidewell
1 Solution
 
david_glidewellAuthor Commented:
I need to do this through VBA Code...  I have to replicate this to over 100 PC's.
0
 
jimbobmcgeeCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now