命令发送到Word没有GUI自动化 [英] Send a command to Word without GUI Automation

查看:347
本文介绍了命令发送到Word没有GUI自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是preferred方法发送到Word命令,而无需使用GUI自动化几乎单击菜单和按钮?我指的是,可以通过GUI进行访问的命令,如设置字体样式,添加对象,添加艺术字等。

What is the preferred method to send a command to MS Word without using GUI automation to virtually click menus and buttons? I'm referring to commands that can be accessed via the GUI, such as setting font style, adding objects, adding WordArt, etc.

Word.Interop 允许这一点,但许多在GUI可用的命令丢失或需要一点code,以获得它的工作完全一样的图形用户界面的命令。例如,GUI具有一个命令复制选定的文本,但是这需要一个行$ C $的c

Obviously Word.Interop allows for this, but many of the commands available in the GUI are missing or needs a bit of code to get it working exactly like the GUI command. For example, the GUI has a command to copy selected text, but that needs a line of code :

ActiveDocument.ActiveWindow.Panes(1).Selection.Copy

我要找的命令列表Word具有相匹配的大型命令列表:

I'm looking for a large command list that matches the list of commands that Word has:

应该是这样的: Word.SendCommand(AddShapeAfter);

有没有这样的系统?

推荐答案

如何这样的事情? -

How about something like this? -

string command = "Copy";
bool flag= Globals.ThisAddIn.Application.CommandBars.GetEnabledMso(command);
if (flag)
{
    Globals.ThisAddIn.Application.ActiveDocument.CommandBars.ExecuteMso(command);
}

这篇关于命令发送到Word没有GUI自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆