Moving an Add-In Button

K

Kevin

I Have an Add-In that creates a menu item under the FILE menu. Add works
great, I just want to know hoe to move the button up from below the EXIT
command. Obviously I could use the customize and move it manually but I'm
adding this COM Add-In to 200 systems and I don't want to do it manually.

Here's my sample
' Constants for menu item in Office application.
Public Const CBR_NAME As String = "File" 'menu name
Public Const CTL_CAPTION As String = "Save to Drive"
Public Const CTL_KEY As String = "SavetoDrive"
Public Const CTL_NAME As String = "Save to Drive"

Function CreateAddInCommandBarButton(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object) As Office.CommandBarButton

' This procedure assigns a reference to the Application
' object passed to the OnConnection event to a global
' object variable. It then creates a new command bar
' button and returns a reference to the button to the
' OnConnection event procedure. The advantage to
' putting this code in a public module is that if you
' have more than one add-in designer in the project, you can
' call this procedure from each of them rather than
' duplicating the code.

Dim cbrMenu As Office.CommandBar
Dim ctlBtnAddIn As Office.CommandBarButton

' Return reference to Application object and store it in public variable
' so that other procedures in add-in can use it.
Set gobjAppInstance = Application.ActiveExplorer

' Return reference to command bar.
Set cbrMenu = gobjAppInstance.CommandBars(CBR_NAME)

' Add button to call add-in from command bar, if it doesn't
' already exist.
' Constants are declared at module level.
' Look for button on command bar.
Set ctlBtnAddIn = cbrMenu.FindControl(Tag:=CTL_KEY)
If ctlBtnAddIn Is Nothing Then
' Add new button.
Set ctlBtnAddIn = cbrMenu.Controls.Add(Type:=msoControlButton, _
Parameter:=CTL_KEY)
' Set button's Caption, Tag, Style, and OnAction properties.
With ctlBtnAddIn
.Caption = CTL_CAPTION
.Tag = CTL_KEY
.Style = msoButtonCaption
' Use AddInInst argument to return reference
' to this add-in.
.OnAction = PROG_ID_START & AddInInst.ProgId _
& PROG_ID_END
' .Picture = picPicture

End With
End If

' Return reference to new commandbar button.
Set CreateAddInCommandBarButton = ctlBtnAddIn


Thanks in advance.
Also if anyone know how to add a custom icon programatically please le me
know.

Kevin
(e-mail address removed)
 
K

Ken Slovak - [MVP - Outlook]

The CommandBarControls.Add method has a Before argument you can supply to
place the control where you want it. You can get the control you want to
place your button before and get its Index property. Then use Before :=
lngIndex where lngIndex is the index you stored.

To place an icon on a button face you can use PasteFace for Outlook 2000 and
later. You place the icon on the Clipboard and PasteFace takes it from the
clipboard and puts it on the button. Outlook 2002 and later also have the
Picture and Mask properties that can directly work with an image and mask.

A good idea when using PasteFace is to get the current Clipboard contents,
save them, load your image and paste it and then restore the previous
contents of the Clipboard. That's much user friendlier than overwriting the
user's Clipboard.

An image for a button should be a BMP that is 16x16 with 256 colors to
conform to the Office specs.
 

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