Create a custom toolbar

G

Guest

I have a macro to insert text in the subject line and message box of a new
mail message. I can create a custom toolbar button on the new mail message
Standard toolbar. I know that I can save the VBProject.OTM on the person's
hard drive but they must assign the toolbar button. The question I have is
if there is a way to distribute this solution to other users without them
having to assign the macro to a toolbar?
 
M

Michael Bauer

Am Tue, 28 Feb 2006 14:02:31 -0800 schrieb Rhonda:

You can create a CommandBar by code. Here´s a sample. You can call the
CreateCommandBarButton function from within the NewInspector event. For the
ability to use more than one Inspector at once you´d need an Inspector
wrapper; a sample is at:
http://www.slovaktech.com/code_samples.htm#InspectorWrapper

Private WithEvents Button As Office.CommandBarButton

Private Sub Button_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
'
End Sub

Private Function CreateCommandBarButton(oBars As Office.CommandBars) As
Office.CommandBarButton
On Error Resume Next
Dim oMenu As Office.CommandBar
Dim oBtn As Office.CommandBarButton
Const BAR_NAME As String = "YourCommandBarName"
Const CMD_NAME As String = "YourButtonName"

Set oMenu = oBars(BAR_NAME)
If oMenu Is Nothing Then
Set oMenu = oBars.Add(BAR_NAME, msoBarTop, , True)
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, , True)
oBtn.Caption = CMD_NAME
oBtn.Tag = CMD_NAME

Else
Set oBtn = oMenu.FindControl(, , CMD_NAME)
If oBtn Is Nothing Then
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, , True)
End If
End If

oMenu.Visible = True
Set CreateCommandBarButton = oBtn
End Function
 
G

Guest

Thanks Michael,

I am new to the WithEvents function. Where should I place this code, at the
module level or in a separate module?
 
D

Dave Kane [MVP - Outlook]

This would all go in ThisOutlookSession. The Button object is a module-level
variable. The WithEvents keyword tells VBA to create handlers for any events
that the object exposes - you will see "Button" (or whatever variable name
you choose) in the left-hand dropdown above the code window, where
"(General)" and "Application" currently appear. The Click event will appear
in the right-hand dropdown when "Button" is selected in the left.
 
G

Guest

Hi,

I'm trying to do something similar. I have a sub which launches the
application we need to launch.

I can manually attach this to a button in a toolbar, but we want to roll
this out to all users in the organisation. Is there some VBScript style code
we can run on login which will add the button and the appropriate _click code
to their workstation?

Thanks,
Carl
 
S

Sue Mosher [MVP-Outlook]

The right solution would be to develop this as an Outlook add-in and install the add-in on each machine.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

I'm trying to use this code. Where do I make changes to link the button to
the macro? Is it possible to assign an icon to the button? I have two
macros, so I would like two buttons is this possible?

In the button part of the script, do I need to add some code where the ' is?

I have no experience with this sorry to be a burden!

Matt
 

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