我可以更改 Word 2007 中“插入表格”命令的行为吗?
在 Word 2007 中,“插入”功能区选项卡有一个“表格”组,其中有一个下拉按钮(标记为“表格”)。
下拉列表包含各种菜单项,例如“插入表格...”、“绘制表格”等。但是,在下拉列表的顶部有一个 10x8 网格,您可以使用它来快速选择表格的大小。使用鼠标新建表格。 (第一个问题:这东西到底叫什么?!!)。
我想覆盖默认行为,以便当用户使用上面提到的小部件“绘制”表格时,我可以更改表格中使用的段落样式(也许还可以进行一些其他清理)。
我知道如何覆盖“插入表...”命令,但我不知道如何覆盖“小部件”的行为。能做到吗?
In Word 2007, the "Insert" ribbon tab has a "Tables" group with a single drop-down button (labelled "Table").
The drop-down contains various menu items such as "Insert Table...", "Draw Table", etc. However, at the top of the drop-down there's a 10x8 grid that you can use to quickly choose the size of your new table using the mouse. (First question: what the heck is this thing called?!!).
I'd like to override the default behaviour, so that when the user "draws" a table using the widget mentioned above, I can change the paragraph style used within the table (and perhaps do some other clean-up).
I know how to override the "Insert Table..." command, but I can't figure out how to override the behaviour of the "widget". Can it be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你继续阅读之前(因为这会很长)我想说我没有解决这个问题。然而,在我尝试解决并解决这个问题时,我发现了很多事情,我将其记录在这里,希望它们能帮助其他人找到解决方案。
在尝试确定可用于插入表格的 10x8 网格的控件时,我发现了 Word 命令中列出的一个名为“TableInsertGeneral”的宏。
根据 Suzanne S. Barnhill 的说法,如果此功能停止,该宏将恢复网格早期版本的 Word 中的函数 (插入表格下拉菜单丢失)。该宏存在于 Word 2007/2010 中,无法从宏对话框的“运行”按钮执行。双击该命令会关闭该对话框,但不会明显执行任何其他操作。我还尝试通过创建一个名为 TableInsertGeneral 的 VBA 子程序来拦截其功能,但是当我访问网格时,我放入此子程序中的代码似乎并未执行。然而,根据我的研究,我相信 TableInsertGeneral 宏确实与显示 10x8 网格有一些联系。
我还尝试通过更改 Word 功能区中的表格库来解决该问题。因为我无法直接访问控制网格的任何代码,所以我尝试隐藏表格库,然后将其替换为排除网格功能的重建库(从而允许段落样式和其他更改全局工作)。
首先,我下载了一些工具:
使用自定义 UI 编辑器对于 Microsoft Office(它允许编辑 Word 2007 文档或模板中的 customui.xml 文件,而无需创建文件夹结构或维护 xml 文件之间的关系),我打开了一个模板并将此代码保存在文件:
这成功隐藏了原始表库,并用原始表库的一些功能替换了它。 10x8 网格消失了,但我无法恢复“绘图表”切换按钮和“快速表”库。据我所知,XML 架构不允许将其中任何一个(存在于 Word 2007 的开箱即用版本中)嵌入到现有图库中。因为我不喜欢删除功能(即使对于这个部分解决方案,我认为不会使用它),我添加了一个绑定到消息框的按钮作为重建库中的第一项:
用于连接新的“通过网格绘制表格已删除”按钮的代码被放置在名为 RibbonControl 的模块中:
我不希望有人使用这个部分解决方案,然而,如果可以找到恢复两个缺失控件的方法,这可能是一个很好的解决方法。顺便说一句,我改编自 Greg Maxey 的网站:
自定义功能区
如果您读到这里,谢谢!祝愿你通过自己的努力取得更大的成功。
Before you read on (because this will be long) I want to say that I did not solve this problem. However, in my attempts to solve -- and then work around -- this issue, I discovered quite a few things, which I am recording here in the hope that they will help someone else find the solution.
While trying to determine what controls the 10x8 grid that one can use to insert a table, I discovered a macro listed within the Word commands named "TableInsertGeneral".
This macro, according to Suzanne S. Barnhill, will restore the grid if this feature ceases to function in earlier versions of Word (Insert Table Drop Down Missing). The macro, as it exists in Word 2007/2010, cannot be executed from the macro dialog box Run button. Double-clicking on the command dismisses the dialog box, but does not overtly do anything else. I additionally tried to intercept its function, by creating a VBA sub named TableInsertGeneral, but code I placed into this sub did not appear to be executed when I accessed the grid. However, based on my research I believe the TableInsertGeneral macro does have some connection to displaying the 10x8 grid.
I also attempted to work around the problem by altering the Tables Gallery in the Word Ribbon. Because I could not directly access any code that controlled the grid, I attempted to hide the Tables Gallery and then replace it with a rebuilt gallery that excluded the grid function (thus allowing the paragraph style and other changes to work globally).
First I downloaded some tools:
Using the Custom UI Editor for Microsoft Office (which allows one to edit the customui.xml file inside a Word 2007 document or template without needing to create folder structures or maintain relationships between xml files) I opened a template and saved this code within the file:
This successfully hid the original Tables gallery and replaced it with some of the functionality of the original Tables gallery. The 10x8 grid was gone, but I was unable to restore the Draw Table toggle button and Quick Tables gallery. As far as I can tell, the XML schema does not allow for embedding either of these (which exist in the out-of-the-box version of Word 2007) into an existing gallery. Because I do not like removing functionality (even for this partial solution, which I did not think would be employed), I added a button tied to a message box as the first item in the rebuilt gallery:
The code for connecting the new "Draw Table Via Grid Has Been Removed" button was placed in a module named RibbonControl:
I do not expect anyone to use this partial solution, however, if a means for restoring the two missing controls could be achieved, this might be a good workaround. By the way, I adapted most of this from Greg Maxey's Web site:
Customizing the Ribbon
If you read this far, thanks! And I wish you more success with your own attempts.