Outllok 2002 Custom Toolbar OnAction property

D

Dick

I am trying to build a VBA utility which will help me document Outlook
2002 custom toolbars. I want the utility to extract a number of
properties, whether the toolbar pertains to Explorer or Inspector. The
property that is giving me problems is the OnAction property. The code
runs okay; I get an output list of various properties, but the OnAction
property is always blank.

I have looked in Sue Mosher's book (Microsoft Outlook Programming:
Jumpstart for Administrators, Power Users, and Developers) for some
tips. The code in Listing 21.4: Build a List of All Command Bars and
Commands, grabs the Caption property, but not the OnAction property.
Table 21.4: Key CommandBarButton Properties, describes the OnAction
property as "The name of the VBA macro to run when the control is
clicked or its value is changed".

I must be missing something. I hope someone can help me make sense of
how to capture the name of the macro which is to be run when a custom
button is clicked.

Thanks in advance.
 
K

Ken Slovak - [MVP - Outlook]

Have you checked on some CommandBarButton that actually has an OnAction
macro defined? If nothing was added to that property I'd expect it to return
a Null string.
 
D

Dick

Ken,

Thanks for your reply. I created these custom toolbars and assigned
macros to them. They perform the intended actions when I click on them.
But when I use VBA code to grab the OnAction property it is returning a
blank value.

Dick
 
K

Ken Slovak - [MVP - Outlook]

Hmm. I ran this quickie test code that creates a toolbar above the main menu
bar and was able to retrieve the OnAction value. It also worked when
"NewAction" used Debug.Print to print out the OnAction value.

Public Sub TestOnActionValue()
Dim oCB As Office.CommandBar
Dim oCBB As Office.CommandBarButton

Set oCB = Application.ActiveExplorer.CommandBars.Add("Foobar", , , True)

With oCB
.Position = msoBarTop
.Left = 0
.Top = 0
.RowIndex = msoBarRowFirst
.Visible = True
End With

Set oCBB = oCB.Controls.Add(msoControlButton, , , , True)

With oCBB
.Caption = "&Test"
.OnAction = "NewAction"

Debug.Print .OnAction
End With

Set oCB = Nothing
Set oCBB = Nothing
End Sub

Private Sub NewAction()
Dim oCB As Office.CommandBar
Dim oCBB As Office.CommandBarButton

Set oCB = Application.ActiveExplorer.CommandBars.Item("Foobar")

Set oCBB = oCB.Controls.Item(1)
Debug.Print oCBB.OnAction


Set oCB = Nothing
Set oCBB = Nothing
End Sub
 
D

Dick

Ken,

Thanks again. I tried out the following code:

Dim oCB As Office.CommandBar
Dim oCBB As Office.CommandBarButton

Set oCB = Application.ActiveExplorer.CommandBars.Item("Dick - Side
Exporer")

Set oCBB = oCB.Controls.Item(1)
Debug.Print "Caption: " & oCBB.Caption
Debug.Print "Action: " & oCBB.OnAction

Set oCB = Nothing
Set oCBB = Nothing


However, in the Immediate window I got the following:
Caption: Tips
Action:

I guess Outlook doesn't like me very much. :)

On the off chance that the problem is my References, here is a list:

Outlook 2002 VBE References:
 
D

Dick

One other thought. I did not use VBA to create the toolbars/buttons
originally. Could that be an issue?
 
K

Ken Slovak - [MVP - Outlook]

That should only be an issue if you aren't getting a valid CommandBar
object. You can certainly test for that using If Not(oCB Is Nothing) Then
and putting the rest of the code under that If statement.
 
K

Ken Slovak - [MVP - Outlook]

The only references you would need for that would be Outlook and Office.
 
D

Dick

I don't think that is my problem, or else I would not get a value back
for the button caption property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top