public override void RunCommand(object sender) { var engine = (AutomationEngineInstance)sender; var vFilePath = v_FilePath.ConvertUserVariableToString(engine); if (v_CloseAllInstances == "Yes") { var processes = Process.GetProcessesByName("winword"); foreach (var prc in processes) { prc.Kill(); } } var newWordSession = new Application(); if (v_Visible == "Yes") { newWordSession.Visible = true; } else { newWordSession.Visible = false; } newWordSession.AddAppInstance(engine, v_InstanceName); if (v_NewOpenDocument == "New Document") { if (!string.IsNullOrEmpty(vFilePath)) { throw new InvalidDataException("File path should not be provided for a new Word Document"); } else { newWordSession.Documents.Add(); } } else if (v_NewOpenDocument == "Open Document") { if (string.IsNullOrEmpty(vFilePath)) { throw new NullReferenceException("File path for Word Document not provided"); } else { newWordSession.Documents.Open(vFilePath); } } }