Word 2010: how to create a drop-down menu in qat (quick access toolbox)

北城余情 提交于 2020-01-04 13:42:10

问题


SHORT: I would like to add a drop-down menu to the quick access toolbar of any instance of Word 2010 via placing a customized .dotm-file in Word's startup folder. I fail in creating this customized .dotm-file.

LONG: I've been writing a little "add-in" for Word 2010, first with VSTO, then figured out problems with the deployment, now with VBA. The add-in should simplify adding my company's logo and legal notice to documents (different combinations of logos & legal notices exist).

In order to allow selection of wished logo and legal notice with as few clicks as possible, I thought about automatically adding a drop-down menu to the quick access toolbar (qat). I want to do this by placing a .dotm-file containing the code for this qat-extension & the logic for the header/footer-setting in the user's Word startup-folder.

I have already succeded in adding such a drop-down menu to the Add-Ins-Ribbon using CustomUI, everything works fine on the code side. Via the menu the user can choose from all presets supplied and headers and footers are added successfully.

Furthermore, I have seen and played with examples that successfully add controls directly to the qat.

If placed in my startup-folder, these examples do a perfect job and the controls defined therein appear on any instance of Word. The way to go is to create a new folder "userCustomization" in the .dotm-document and then create the customUI.xml-file with several restrictions (no custom icons allowed e.g.).

Unfortunately, I was not able to figure out how to implement a drop-down-menu control in the qat. All the examples I found only used "simple" (button) controls and no matter how many times whatsoever I tried wrapping buttons in a tag, i never got it working.

I can on the other hand manually add my ribbon via "qat => add controls" to the qat and .. voilà .. it's there, working exactly as wanted, so i suppose it must be possible. But what I need is to automate this so that our users don't have to do any configuration of the qat.

Help would be very much appreciated! Best regards from Germany, Kurt

This is how the drop-down menu is added to the Add-Ins-tab:

<ribbon>  
<tabs>  
<tab idMso="TabAddIns">    
<group id="MyGroup" label="WordDesigner" visible="false">       

    <menu id="myMenu" label="Design einfügen" size="large" image="menulogo">
    <menu id="mySubMenu" label="Rechnungswesen" image="icon2">  
        <button id="MahnUndKlage"  label="Mahn- und Klage" image="icon3" onAction="DesignAnwenden"/> 
        <button id="Buchhaltung"  label="Buchhaltung" image="icon3" onAction="DesignAnwenden"/>    
    </menu>
    <button id="Personalabteilung"  label="Personalabteilung" image="icon3" onAction="DesignAnwenden"/>
    <button id="Verkauf"  label="Verkauf" image="icon4" onAction="DesignAnwenden"/>
    <button id="clearHeaderAndFooter"  label="Gestaltung entfernen" image="icon5" onAction="DesignAnwenden"/>   
    </menu>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Usefull information I found included:

  • Greg Maxey on modifying icons in the qat
  • in german, part 18 of an introduction to RibbonX

回答1:


Alright, some more research has led to some more information ( ... ) and in case anybody else might ever search for a similar question, I'll try to conclude what i got..

  • 1) According to this MS page on the QAT, only Button, ToggleButton and CheckBox are valid items for the QAT in Win7 (Win8 allows some more controls).

  • Since you can manually add drop-down-menus as well, I thought there had to be some way to do that automatically as well as with buttons, checkboxes and togglebuttons

  • I could for the life of me not figure out a way to auto-add a drop-down to the QAT by modifying the customUI.xml-file in the userCustomization-Folder of a .dotm-file in startup folder.

  • There is one other possibility to achieve that goal: Office 2010 uses a file of the type ".officeUI" where it stores each users elements from the QAT (e.g. Word.officeUI). In there, adding the following xml-Element will make sure that, if you have placed the .dotm-file containing your menu in Word's startup folder, it is on load displayed as a drop-down in the QAT:

    <mso:control idQ="x1:myMenu" visible="true"/>

  • Unfortunatly, enthusiastically adding this xml-Element to the customUI.xml in userCustomization results in .. poof .. no user defined extra icons in the QAT at all (customUI.xml is corrupt).

Furthermore, a great ressource I stumbled upon yesterday is Andy Pope's Visual Ribbon Editor. You can easily tweak the Ribbon and QAT.




回答2:


I know I'm late to the game, but I found this post via Google and figured you'd appreciate an answer.

You can create the appearance of a menu through Word's QAT with a little VBA trickery. Basically, create a custom command bar with each "Control" representing a slot on your desired menu. You can use ".BeginGroup" to create a divider line to separate items if you wish. Your menu can go at least a couple levels down, but for complexity's sake, I wouldn't recommend going too deep.

When your command bar is perfect, create a macro that only displays your command bar as a popup when run:

    Application.CommandBars("My Command Bar").ShowPopup

Add a shortcut to that macro to the QAT. When you click that shortcut, your command bar will appear as a popup menu at your cursor, which is the desired effect.

Enjoy!



来源:https://stackoverflow.com/questions/14390300/word-2010-how-to-create-a-drop-down-menu-in-qat-quick-access-toolbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!