Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Word 2007: executing a custom add-in button programatically

Posted on 2009-03-31
4
Medium Priority
?
1,752 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:DonQuiyote
ID: 24037116
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
ID: 24039737
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 1500 total points
ID: 24046176
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
ID: 24055214
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lately there has been a variety of news related to U.S. employment.  Stories about worker productivity, automobile and airline unions, low employment and foreign laborers have frequented the news.  Each story has good and bad attributes we might arg…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

661 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