Send a command to Word without GUI Automation

只谈情不闲聊 提交于 2019-12-11 19:05:32

问题


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.

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

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

It should be something like : Word.SendCommand("AddShapeAfter");

Is there any such system?


回答1:


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);
}


来源:https://stackoverflow.com/questions/21250279/send-a-command-to-word-without-gui-automation

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