Question

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:

Cmds

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

Is there any such system?

Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top