Solved

Word 2007: executing a custom add-in button programatically

Posted on 2009-03-31
4
1,665 Views
Last Modified: 2012-06-27
I am in the process of migrating a body of Word automation from Word 2000 to 2007.

In Word 2007, the ExecuteMso method has been added, which allows programatically invoking the action associated with any built-in button.

I need to invoke the action associated with a button that a COM add-in has added to the Office Button menu, however; and I have not been able to locate a method for doing so.

Any guidance will be greatly appreciated.
0
Comment
Question by:dlhumphrey
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:DonQuiyote
Comment Utility
You'll need to clarify what you mean by the button menu. When a com modifies the menu in Word 2007, this typically appears in the Add-Ins tab of the ribbon, in bar of its own with one or more buttons. Is that so?
In that case you do not need ExecuteMso.

Find the internal name of the bar by executing the following macro in a bland document. (Alt F11, paste it into New Macros and press F5 with the cursor within the procedure).

Then use the following macro to find the name of the control button in that bar (probably just one?). Once you have the internal name of the commandbar ,search it with the second macro for the macros that are triggered when the button is clicked ('onAction'). That's the name of the macro you want to invoke. (Note that most commandbars listed are not visible, and include legacy controls for compatibility with old macros)

Sub listBars()

' Paste this code into the NewMacros module of the Normal Template (Alt-F11 to open VBA editor)

' Press F5 to execute directly from here and paste list into new document.

' Then return to the active document to view the list and continue.

Dim cbar

Documents.add

Selection.TypeText "Full list of command bars" + vbCr

Selection.TypeText "CommandBar Caption: ... CommandBar name: ..." + vbCr

For Each cbar In CommandBars

    Selection.TypeText cbar.NameLocal + "= " + cbar.Name + vbCr

Next

Selection.TypeText vbCr + "Now select the command bar to examine and double-click here: "

ActiveDocument.Fields.add Range:=Selection.Range, Type:=wdFieldEmpty, text:= _

        "MACROBUTTON listControls Find control", PreserveFormatting:=False

        

End Sub
 

Sub listControls()

Dim ctl, cbName As String

With Selection

On Error Resume Next ' some built in bars refuse to reeal information

.Collapse wdCollapseEnd

.TypeText vbCr

cbName = InputBox("Name of command bar to search?")

.TypeText "Searched commandbar '" + cbName + "'" + vbCr

.TypeText "Caption: ... onAction: ..." + vbCr

For Each ctl In CommandBars(cbName).Controls

    .TypeText ctl.Caption + "= " + ctl.OnAction + vbCr

Next

End With

End Sub

Open in new window

0
 

Author Comment

by:dlhumphrey
Comment Utility
Thank you for the explanation and code samples, DonQuiyote.  The situation I've got is a little different, however.  You are right that I need to offer a better description.
The COM add-in I'm dealing with is a DMS (Worksite Office 2007 Integration). It adds a Ribbon tab of its own to allow access to some DMS functionality, but also it adds buttons to the Office Button menu - i.e., officeMenu, the dropdown accessed via the Office Button at top left of window (as do some other COM add-ins, such as Adobe's PDFMaker).

The specific button I need to execute is named WordWorkSiteSave -- this I got by adding the button to the QAT and viewing the Word.qat file (XML). The COM add-in's namespace is oUTR02K.Connect.

In the Word Options | Customize dialog, if I hover the pointer above the button corresponding to the one on the officeMenu, Word indicates in parentheses, the way an mso name would be, CustomControl.
I need to get a reference in code to the CustomControl named WordWorkSiteSave , added to the officeMenu by the COM add-in oUTR02K.Connect so that I can execute it whenever a user creates a new document.
0
 
LVL 1

Accepted Solution

by:
DonQuiyote earned 500 total points
Comment Utility
All right you seem familiar with setting up a macro and finding the information that is available.
'If' the COM makes its interface available, then you should be able to add a reference from your project, and then see in Object Browser the list of public procedures. In the VB Editor use tools, references. Either look through the list, or directly browse to the COM add-in if you know to locate it. Let me know how you get on.
0
 

Author Comment

by:dlhumphrey
Comment Utility
The WorkSite DMS COM add-in exposes a lot of automation -- in fact, all that the WordWorkSiteSave button does can be done from within VBA, call by call.  (In an earlier version of the DMS, that was in fact necessary.)
Unfortunately the vendor dev support started me looking down the unfruitful ExecuteMSO path; they indicated there might be no straightforward way to reference and execute their button but suggested it might be possible round-aboutly through that method, somehow or other.
Looking more deeply than previously through the exposed WorkSite objects, today I located a class added specifically for Word 2007 that includes a method that appears to execute the WordWorkSiteSave button .  
Still, the method requires passing a reference to the button -- but existence of the method implies to me that someone at the vendor knows how to do that.  Next step I see is to go back to their dev support to inquire pointedly about this class and method that they seem to have been unaware of previously.
Thanks for your time and input, DonQuiyote.  You get the points on this.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
As freelancing is becoming more and more common in the tech industry, certain obstacles are proving to be a challenge to those who are used to more traditional, structured employment. This article is meant to help identify such obstacles and offer a…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now